localdatetime java example 1

localdatetime java example

LocalDateTime current=LocalDateTime.now();//gets current LocalDateTime
LocalDateTime dateTime=LocalDateTime.of(year,month,day,hour,minute,second);//gets specific LocalDateTime
dateTime.getHour();//get the hour of a DateTime
dateTime.getDayOfWeek();//get number of current day in week
dateTime.isBefore(someOtherDateTime);//checks if it is before another LocalDateTime
dateTime.toLocalDate();//converts it to a LocalDate
dateTime.toLocalTime();//converts it to a LocalTime

Here is what the above code is Doing:
1. It gets the current LocalDateTime
2. It gets a specific LocalDateTime
3. It gets the hour of a DateTime
4. It gets the number of the current day in the week
5. It checks if it is before another LocalDateTime
6. It converts it to a LocalDate
7. It converts it to a LocalTime

Similar Posts