java.time


1. Getting the Current Date and Time

LocalDateTime now = LocalDateTime.now();
System.out.println(now);

2. Creating a Specific Date and Time

LocalDate birthDate = LocalDate.of(1980, 1, 1);
LocalTime birthTime = LocalTime.of(12, 30);
LocalDateTime birthDateTime = LocalDateTime.of(birthDate, birthTime);

3. Adding and Subtracting Time

LocalDateTime now = LocalDateTime.now();
LocalDateTime later = now.plusHours(2);
LocalDateTime earlier = now.minusMinutes(30);

4. Comparing Dates and Times

LocalDate date1 = LocalDate.of(2023, 3, 8);
LocalDate date2 = LocalDate.of(2023, 3, 10);
boolean isDate1BeforeDate2 = date1.isBefore(date2);

5. Parsing and Formatting Dates and Times

String dateString = "2023-03-08";
LocalDate date = LocalDate.parse(dateString);

String formattedDateString = date.format(DateTimeFormatter.ofPattern("dd/MM/yyyy"));

6. Converting Between Time Zones

7. Calculating Differences Between Dates and Times

8. Getting Weekday and Day of Year

9. Checking for Temporal Validity

10. Creating Time Ranges

11. Converting to and from Epoch Time

12. Managing Daylight Saving Time (DST)

13. Creating TimeStamp

14. Creating Timer Schedules

15. Getting Today's Date

16. Getting Month Value

17. Creating Interval

18. Getting Year

19. Getting Day Value

20. Checking if Year is Leap Year

21. Getting Time Zone

22. Getting Offset from UTC

23. Creating Duration

24. Adding Duration to Instant

25. Calculating Duration Between Two Instants

26. Creating Period

27. Adding Period to LocalDate

28. Calculating Period Between Two LocalDates

29. Creating OffsetDateTime

30. Getting Offset

31. Creating ZoneId

32. Creating ZoneDateTime

33. Creating Duration from Nanoseconds

34. Creating Duration from Milliseconds

35. Calculating Duration Between Two LocalDateTime

36. Converting LocalDateTime to Epoch Seconds