Working with Local and Zoned Time in Java

Tharaka Dissanayake
2 min readJul 19, 2022

--

There are many time zones in the world. Some countries have one time zone and some have several time zones. So when developing applications developers must care about time zones. A time zone is a geographical area that adheres to a consistent standard time for legal, commercial, and social purposes

Time API of Java

Java introduces a Date-Time API with Java8. It comes with the package java.time. It contains Local and Zoned time classes.

Local Date Time class

The Local Date Time class is used to develop local dates. The LocalDateTime class is immutable and Its object represents date and time with this formatter “yyyy-MM-dd-HH-mm-ss.zzz.”

Get the current time with the Date and Time class.

e can change the pattern of the printing date and time.

ZonedDateTime class

If we want to create applications to work with different time zones we must use the ZonedDateTime class.

SQL Date, SQL Time and SQL Timestamp

Java has another package called java.sql. It has SQL Date, SQL Time and SQL Timestamp classes. It did not contain time zones.

--

--

Tharaka Dissanayake
Tharaka Dissanayake

No responses yet