ZonedDateTime in Java with examples

In this tutorial, we will learn about the Java ZonedDateTime class.

ZonedDateTime in Java

Java ZonedDateTime class which is immutable. This class is a representation of date-time with a time-zone. ZonedDateTime class is used to store all the data and the time field with the utmost precision of nanoseconds.

For Example:-


A ZonedDateTime holds a state equivalent to three different objects they are:-

  1. LocalDateTime
  2. ZoneId (specifies a time zone identifier, provides a rule for converting between an Instant and a LocalDateTime.)
  3. ZoneOffset. (represent the fixed zone offset from UTC zone)

Methods of ZonedDateTime 

  1. now
  2. of
  3. ofLocal
  4. ofInstant
  5. ofStrict
  6. from
  7. parse
  8. isSupported
  9. range
  10. get and many more…


import java.time.ZonedDateTime;  
import java.time.Period;  
public class Time{  
  public static void main(String[] args) {  
      ZonedDateTime zone=;  
    ZonedDateTime m = zone.minus(Period.ofDays(126));  


  •  Import the following classes from java.time package to work with the date and time API in Java.
import java.time.ZonedDateTime; 

import java.time.Period;
  • Declare the main class and declare the main method which is in the entry point of any java program.
  • which returns the current date-time default timezone of your machine.
  • zone. minus used to subtract the number of days from the machine.
  • Period.ofDays() accepts a single parameter which is the number of days to be parsed into the object.


ZonedDateTime in Java


Leave a Reply

Your email address will not be published. Required fields are marked *