107
Java LocalDateTime class
Java LocalDateTime class is an immutable date-time object that represents a date-time, with the default format as yyyy-MM-dd-HH-mm-ss.zzz. It inherits object class and implements the ChronoLocalDateTime interface.
Java LocalDateTime class declaration
Let’s see the declaration of java.time.LocalDateTime class.
Methods of Java LocalDateTime
Method | Description |
---|---|
String format(DateTimeFormatter formatter) | It is used to format this date-time using the specified formatter. |
int get(TemporalField field) | It is used to get the value of the specified field from this date-time as an int. |
LocalDateTime minusDays(long days) | It is used to return a copy of this LocalDateTime with the specified number of days subtracted. |
static LocalDateTime now() | It is used to obtain the current date-time from the system clock in the default time-zone. |
static LocalDateTime of(LocalDate date, LocalTime time) | It is used to obtain an instance of LocalDateTime from a date and time. |
LocalDateTime plusDays(long days) | It is used to return a copy of this LocalDateTime with the specified number of days added. |
boolean equals(Object obj) | It is used to check if this date-time is equal to another date-time. |
Java LocalDateTime Example
Output:
Before Formatting: 2017-01-13T17:09:42.411 After Formatting: 13-01-2017 17:09:42
Java LocalDateTime Example: now()
Output:
14-01-2017 11:42:32
Java LocalDateTime Example: get()
Output:
1 44 13 15 956
Java LocalDateTime Example: minusDays()
Output:
Before Formatting: 2016-10-06T10:34 After Formatting: 06-10-2016 10:34
Java LocalDateTime Example: plusDays()
Output:
Before Formatting: 2017-05-14T10:34 After Formatting: 14-05-2017 10:34
Next TopicJava MonthDay