Running this piece of code and printing formatDateTime would yield: 08:00:00 String formatDateTime = localDateTime.format(formatter) You can also easily format this LocalDateTime into a more readable format: DateTimeFormatter formatter = DateTimeFormatter.ofPattern( "yyyy-MM-dd HH:mm:ss") The "Time" marker simply represents a line between the LocalDate and LocalTime parts of the format. It represents a combination of date and time, and can be used for many purposes: LocalDateTime localDateTime = LocalDateTime.parse( "T08:00:00") The LocalDateTime is the most used class regarding Date/Time in Java. This is the equivalent of writing the proceeding code to instantiate a LocalTime object: LocalTime localTime = LocalTime.of( 8, 00) To convert a string to a LocalTime object, it's enough to write: LocalTime localTime = LocalTime.parse( "8:00") Just like the LocalDate, it provides a lot of very useful parsing and formatting methods built in, as well as the means to add or subtract time from it. It doesn't store time based on the offset since epoch, and it offers nanosecond precision. LocalTime represents time, without a time-zone in ISO-8601 format. ![]() This is the equivalent of writing the proceeding code to instantiate a LocalDate object: LocalDate date = LocalDate.of( 2018, 09, 16) To convert a string to a LocalDate object, it's enough to write: LocalDate date = LocalDate.parse( "") It's also a newer implementation from the Date/Time API and offers its own format/parse method, as well as addition and subtraction of days, weeks and years, which doesn't exist in the Date variant. ![]() It differs from Date in the fact that it doesn't store time as a millisecond offset since epoch, but rather simply the current date. Converting a String to LocalDateĪ LocalDate represents a date, without time in ISO-8601 format. ![]() All date-time classes from this API contain a method for parsing and formatting, where each accepts a DateTimeFormatter to define a pattern. A DateTimeFormatter is used for formatting and parsing date-time objects in the new Date/Time API.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |