Sunday, February 17, 2019

converting ZonedDateTime to Calendar using ThreeTen-Backport (JSR 310)




I am trying to convert a ZonedDateTime object to a Calendar object using the back-port of the java.time classes (JSR 310): the ThreeTen-Backport project.



My understanding was that the back-port was supposed to be similar to functionality on Java 8 (without being on Java 8 itself). Currently, the system is on Java 7.



Whenever I try to execute the following code:



ZonedDateTime zdt = ....
GregorianCalendar newCal = GregorianCalendar.from(zdt);



I get the following message:




The method from(ZonedDateTime) is undefined for the type
GregorianCalendar




I used the following dependency:





org.threeten
threetenbp
1.3.6



How can one come about this problem?



Any help hints or advice would be greatly appreciated.




TIA


Answer





The backport cannot add methods to the JDK. See DateTimeUtils for the conversion methods.



ZonedDateTime zdt = ....
GregorianCalendar newCal = DateTimeUtils.toGregorianCalendar(zdt);


No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...