Adam Cameron
java.util.GregorianCalendar) operations, which results in a value I need being a java.util.Date.
I can't be sure what's going to happen with this value, and it could possibly end up having CFML datetime methods being called on it (eg: myDate.year() etc).
What's the most idiomatic way of forcing the java.util.Date back to a native Lucee date?
My thought is DateAdd("s", 0, myDate) , and whilst that works, it's not immediately clear in the code why I'm doing that.
I'm not adverse to an explanatory comment in this case, but it got me wondering if there's a more "idiomatic CFML" way of doing this?zackster
04/03/2023, 8:01 PMAdam Cameron
Adam Cameron
Michael Schmidt
04/03/2023, 8:22 PMcreateObject("java", "lucee.runtime.type.dt.DateTimeImpl").init(javaUtilDate);Adam Cameron
micha
04/04/2023, 8:41 AMtoString creates a different output (jdbc timestamp based on the timezone set in the lucee enviroment). lucee also can handle “java.util.Date”, no problem. “problem” is when you do myDate.year() you are not calling the year method, you are calling the build in member function year. i think the question is, what do you wanna achieve QM (question mark). but the difference between calling the method or the bif is the timezone used. the method simply uses the jvm default timezone and the bif the lucee env timezone, with the bif you can even define the timezone as argument explicitly. and yes all the date functions in lucee are using the java.util.GregorianCalendar for any date conversion. so using “java.util.Date” natively just has downsides in my opinion, because you will reinvent the wheel for many things. let me know what you wanna do an i can help you with that.micha
04/04/2023, 8:50 AMmicha
04/04/2023, 8:50 AMmicha
04/04/2023, 8:51 AMmicha
04/04/2023, 8:52 AMmicha
04/04/2023, 8:54 AMmicha
04/04/2023, 8:55 AMAdam Cameron
java.util.Date as a native Lucee date type already. So any of the methods listed on https://docs.lucee.org/categories/datetime.html#methods can be called on a java.util.Date?
Thanks - btw - for the very comprehensive answer!Adam Cameron
java.time.* (thanks @seancorfield), and none of it leaks out of the function it's in anyhow, but this is still good info to know.micha
04/04/2023, 12:37 PMMichael Schmidt
04/04/2023, 12:47 PMAdam Cameron