Javatpoint Logo
Javatpoint Logo

Java ZonedDateTime class

Java ZonedDateTime class is an immutable representation of a date-time with a time-zone. It inherits Object class and implements the ChronoZonedDateTime interface.

ZonedDateTime class is used to store all date and time fields, to a precision of nanoseconds, and a time-zone with a zone offset used to handle ambiguous local date-times.


Java ZonedDateTime class declaration

Let's see the declaration of java.time.ZonedDateTime class.

Methods of Java ZonedDateTime

Method Description
String format(DateTimeFormatter formatter) It is used to format this date-time using the specified formatter.
int get(TemporalField field) It is used to get the value of the specified field from this date-time as an int.
ZoneId getZone() It is used to get the time-zone, such as 'Asia/Kolkata'.
ZonedDateTime withZoneSameInstant(ZoneId zone) It is used to return a copy of this date-time with a different time-zone, retaining the instant.
static ZonedDateTime now() It is used to obtain the current date-time from the system clock in the default time-zone.
static ZonedDateTime of(LocalDate date, LocalTime time, ZoneId zone) It is used to obtain an instance of ZonedDateTime from a local date and time.
ZonedDateTime minus(long amountToSubtract, TemporalUnit unit) It is used to return a copy of this date-time with the specified amount subtracted.
ZonedDateTime plus(long amountToAdd, TemporalUnit unit) It is used to return a copy of this date-time with the specified amount added.

Java ZonedDateTime class Example

Test it Now

Output:

2016-10-05T08:20:10+05:30[Asia/Kolkata]

Java ZonedDateTime class Example: of() and withZoneSameInstant()

Test it Now

Output:

In India Central Time Zone: 2017-01-19T15:26+05:30[Asia/Kolkata]
In Tokyo Central Time Zone:2017-01-19T18:56+09:00[Asia/Tokyo]

Java ZonedDateTime class Example: getZone()

Test it Now

Output:

Asia/Kolkata

Java ZonedDateTime class Example: minus()

Test it Now

Output:

2016-09-15T12:54:01.354+05:30[Asia/Kolkata]

Java ZonedDateTime class Example: plus()

Test it Now

Output:

2017-05-25T12:56:12.417+05:30[Asia/Kolkata]
Next TopicJava ZoneId





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA