Differences between Java 8 Date Time API (java.time) and Joda-Time

Common features a) Both libraries use immutable types. Joda-Time also offers additional mutable types like MutableDateTime. b) Furthermore: Both libraries are inspired by the design study “TimeAndMoney” from Eric Evans or ideas from Martin Fowler about domain driven style so they strive more or less for a fluent programming style (although not always perfect ;-)). … Read more

How can I create a Java 8 LocalDate from a long Epoch time in Milliseconds?

If you have the milliseconds since the Epoch and want to convert them to a local date using the current local timezone, you can use LocalDate date = Instant.ofEpochMilli(longValue).atZone(ZoneId.systemDefault()).toLocalDate(); but keep in mind that even the system’s default time zone may change, thus the same long value may produce different result in subsequent runs, even … Read more

cannot resolve symbol ‘java.time.LocalDate’ error in android studio

Android API level 26 Android API level 26 gained an implementation of java.time including your LocalDate class. Earlier Android For Android <26, alternatives include: ThreeTen-Backport is a back-port of much of the java.time functionality to Java 6 & 7. ThreeTenABP adapts ThreeTen-Backport to Android. Joda-Time is commonly used in Android projects. Joda-Time inspired the java.time … Read more

Is there a jackson datatype module for JDK8 java.time?

As already mentioned, Jackson-Datatype-JSR310 provides support for Java 8 Time. Since Jackson 2.6.0 the “old” JSR310Module is deprecated. It is replaced by JavaTimeModule. Maven dependency is the same (you can find the current version in Maven Central): <dependency> <groupId>com.fasterxml.jackson.datatype</groupId> <artifactId>jackson-datatype-jsr310</artifactId> <version>2.6.0</version> </dependency> You have to register the module like this: ObjectMapper mapper = new ObjectMapper(); … Read more

Any difference between java.time.Clock.systemDefaultZone().getZone() vs java.util.TimeZone.getDefault().toZoneId()?

Both returns the JVM’s default timezone (in the end, Clock calls TimeZone.getDefault(), as explained in @Kiskae’s answer), but it’s not guaranteed that all calls will always return the same value everytime. That’s because the default timezone can be changed: the system where the JVM is running can change its configuration. In Windows machines, for example, … Read more

JDK dateformatter parsing DayOfWeek in German locale, java8 vs java9

This seems to be there in java-9 due to the current implementation of CLDR date-time-patterns with the implementation of JEP – 252 which states that Use locale data from the Unicode Consortium’s Common Locale Data Repository (CLDR) by default. Localized patterns for the formatting and translation of display strings, such as the locale name, may … Read more

JPA support for Java 8 new date and time API

For Hibernate 5.X just add <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-java8</artifactId> <version>${hibernate.version}</version> </dependency> and @NotNull @Column(name = “date_time”, nullable = false) protected LocalDateTime dateTime; will work without any additional effort. See https://hibernate.atlassian.net/browse/HHH-8844 UPDATE: Please have a look at Jeff Morin comment: since Hibernate 5.2.x it is enough <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> <version>5.2.1.Final</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-…</artifactId> <version>4.3.1.RELEASE</version> </dependency> See … Read more