Why do Time Zones matter for Developers?
As software developers, we must understand how to deal with date and time because issues resulting from different time zones and daylight savings may arise. Therefore, we initially concentrate on time zones and daylight savings before moving on to the date and time classes used in Java.
The time zone in various countries is varied, as shown in the graphic above.
Daylight Saving Time
This idea was employed to boost productivity during the daytime hours. On the first Sunday in November, at two in the morning, everyone is required by law to turn their clocks back to standard time. That entails setting the clocks back one additional hour at 2 a.m. The morning hours will be a little bit brighter in the winter, but the sun will set sooner in the evening. When the clocks are set forward in March, 2 o’clock in the morning will be 3 o’clock in the morning.
Java API is used to manage date and time in Java.
new classes to manage java date and time were included in the java 8 release. Localdate, localtime, and localdatetime classes were introduced in Java 8 to support date and local time in Java. When the need for time zones is gone, we should use them.
In the ISO-8601 format, the LocalDate class represents a date without a time (YYYY-MM-DD).
LocalDate now = LocalDate.now();
string representation of the current ISO-8601 format
LocalDate localDate = LocalDate.parse(“2021- 12–20”);
a particular day, month, and year
LocalDate localDate = LocalDate.of(2021, 12, 20);
to find the day of the week and the day of the month
DayOfWeek day = LocalDate.now().getDayOfWeek(); //week
int month = LocalDate.parse(“2020–01–12”).getDayOfMonth(); //month
Without considering the timezone, the local date and time are represented by the LocalDateTime class.