Unix epoch time to Java Date object

How about just: Date expiry = new Date(Long.parseLong(date)); EDIT: as per rde6173‘s answer and taking a closer look at the input specified in the question , “1081157732” appears to be a seconds-based epoch value so you’d want to multiply the long from parseLong() by 1000 to convert to milliseconds, which is what Java’s Date constructor … Read more

serialize/deserialize java 8 java.time with Jackson JSON mapper

There’s no need to use custom serializers/deserializers here. Use jackson-modules-java8’s datetime module: Datatype module to make Jackson recognize Java 8 Date & Time API data types (JSR-310). This module adds support for quite a few classes: Duration Instant LocalDateTime LocalDate LocalTime MonthDay OffsetDateTime OffsetTime Period Year YearMonth ZonedDateTime ZoneId ZoneOffset

Convert java.util.Date to java.time.LocalDate

Short answer Date input = new Date(); LocalDate date = input.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); Explanation Despite its name, java.util.Date represents an instant on the time-line, not a “date”. The actual data stored within the object is a long count of milliseconds since 1970-01-01T00:00Z (midnight at the start of 1970 GMT/UTC). The equivalent class to java.util.Date in JSR-310 is … Read more

How to parse/format dates with LocalDateTime? (Java 8)

Parsing date and time To create a LocalDateTime object from a string you can use the static LocalDateTime.parse() method. It takes a string and a DateTimeFormatter as parameter. The DateTimeFormatter is used to specify the date/time pattern. String str = “1986-04-08 12:30”; DateTimeFormatter formatter = DateTimeFormatter.ofPattern(“yyyy-MM-dd HH:mm”); LocalDateTime dateTime = LocalDateTime.parse(str, formatter); Formatting date and … Read more