These classes supplant the troublesome old legacy date-time classes such as, Calendar, & SimpleDateFormat. The java.time framework is built into Java 8 and later. Use the DateTimeFormatter.ofLocalized… methods. Tip: Consider letting java.time automatically localize for you rather than hard-code a formatting pattern. DateTimeFormatter f = DateTimeFormatter.ofPattern( "dd/MM/uuuu" ) Generate a String representing that value using standard ISO 8601 format. ZonedDateTime zdt = instant.atZone( z ) // Same moment, different wall-clock time.Įxtract a date-only value. ZoneId z = ZoneId.of( "Pacific/Auckland" ) For any given moment, the date varies around the globe by zone. The modern approach uses the java.time classes that supplant the troublesome old legacy date-time classes used by all the other Answers.Īssuming you have a long number of milliseconds since the epoch reference of first moment of 1970 in UTC, … Instant instant = Instant.ofEpochMilli( myMillisSinceEpoch ) Tip: Consider using `DateTimeFormatter.ofLocalized…` instead to soft-code the formatting pattern. format( // Generate a string to textually represent the date value.ĭateTimeFormatter.ofPattern( "dd/MM/uuuu" ) // Specify a formatting pattern. toLocalDate() // Extract the date-only value (a `LocalDate` object) from the `ZonedDateTime` object, without time-of-day and without time zone. atZone( ZoneId.of( "Africa/Tunis" ) ) // Adjust into the wall-clock time used by the people of a particular region (a time zone). Tl dr Instant.ofEpochMilli( myMillisSinceEpoch ) // Convert count-of-milliseconds-since-epoch into a date-time in UTC (`Instant`).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |