Posts

Showing posts with the label LocalDateTime

Java 8 LocalDateTime class explained with code samples

Just like the LocalDate and LocalTime classes, Java 8 has also introduced the LocalDateTime class. In this article, I will be covering this class. Edit What is LocalDateTime class? The Java 8 LocalDateTime class represents a date with a time component. It has the year, month, day, hour, minute, second and nanoseconds components. So for example, you can use it to represent a date time like 12th August 1997 7:30 am . LocalDateTime Creation There are several static methods on the LocalDateTime class that can be used to create a LocalDateTime. The following code demonstrates this:   LocalDateTime dateTime1 = LocalDateTime.now();  System.out.println("Today's date is "+dateTime1);    LocalDateTime dateTime2 = LocalDateTime.parse("2019-07-15T10:15:30");  System.out.println("Date2 is "+dateTime2);    dateTime2 = LocalDateTime.of(2017,05,17,5,25);  System.out.println("Date3 is "+dateTime2);   The LocalDateTime.now returns the current time. Th...