Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Java Arrays
  • Java Strings
  • Java OOPs
  • Java Collection
  • Java 8 Tutorial
  • Java Multithreading
  • Java Exception Handling
  • Java Programs
  • Java Project
  • Java Collections Interview
  • Java Interview Questions
  • Java MCQs
  • Spring
  • Spring MVC
  • Spring Boot
  • Hibernate
Open In App
Next Article:
ZonedDateTime now() Method in Java with Examples
Next article icon

ZonedDateTime now() Method in Java with Examples

Last Updated : 21 Jan, 2019
Comments
Improve
Suggest changes
Like Article
Like
Report
In ZonedDateTime class, there are three types of now() method depending upon the parameters passed to it.

now()

now() method of a ZonedDateTime class used to obtain the current date-time from the system clock in the default time-zone.This method will return ZonedDateTime based on system clock with default time-zone to obtain the current date-time. The zone and offset will be set based on the time-zone in the clock. Syntax:
  public static ZonedDateTime now()  
Parameters: This method accepts no parameter. Return value: This method returns the current date-time using the system clock. Below programs illustrate the now() method: Program 1: Java
// Java program to demonstrate // ZonedDateTime.now() method  import java.time.*;  public class GFG {     public static void main(String[] args)     {          // create an ZonedDateTime object         ZonedDateTime lt             = ZonedDateTime.now();          // print result         System.out.println("ZonedDateTime : "                            + lt);     } } 
Output:
  ZonedDateTime : 2019-01-21T05:36:18.973Z[Etc/UTC]  

now(Clock clock)

now(Clock clock) method of a ZonedDateTime class used to return the current date-time based on the specified clock passed as parameter.The zone and offset will be set based on the time-zone in the clock. Syntax:
  public static ZonedDateTime now(Clock clock)  
Parameters: This method accepts clock as parameter which is the clock to use. Return value: This method returns the current date-time. Below programs illustrate the now() method: Program 1: Java
// Java program to demonstrate // ZonedDateTime.now() method  import java.time.*;  public class GFG {     public static void main(String[] args)     {          // create a clock         Clock cl = Clock.systemUTC();          // create an ZonedDateTime object using now(Clock)         ZonedDateTime lt             = ZonedDateTime.now(cl);          // print result         System.out.println("ZonedDateTime : "                            + lt);     } } 
Output:
  ZonedDateTime : 2019-01-21T05:36:25.966Z  

now(ZoneId zone)

now(ZoneId zone) method of a ZonedDateTime class used to return the current date-time from system clock in the specified time-zone passed as parameter.Specifying the time-zone avoids dependence on the default time-zone. The offset will be calculated from the specified time-zone. Syntax:
  public static ZonedDateTime now(ZoneId zone)  
Parameters: This method accepts zone as parameter which is the zone to use. Return value: This method returns the current date-time. Below programs illustrate the now() method: Program 1: Java
// Java program to demonstrate // ZonedDateTime.now() method  import java.time.*;  public class GFG {     public static void main(String[] args)     {          // create a clock         ZoneId zid = ZoneId.of("Europe/Paris");          // create an ZonedDateTime object using now(zoneId)         ZonedDateTime lt             = ZonedDateTime.now(zid);          // print result         System.out.println("ZonedDateTime : "                            + lt);     } } 
Output:
  ZonedDateTime : 2019-01-21T06:36:30.188+01:00[Europe/Paris]  
References: https://docs.oracle.com/javase/10/docs/api/java/time/ZonedDateTime.html#now() https://docs.oracle.com/javase/10/docs/api/java/time/ZonedDateTime.html#now(java.time.Clock) https://docs.oracle.com/javase/10/docs/api/java/time/ZonedDateTime.html#now(java.time.ZoneId)

Next Article
ZonedDateTime now() Method in Java with Examples

A

AmanSingh2210
Improve
Article Tags :
  • Java
  • Java-Functions
  • Java-time package
  • Java-ZonedDateTime
Practice Tags :
  • Java

Similar Reads

    ZonedDateTime plusNanos() method in Java with Examples
    plusNanos() method of a ZonedDateTime class used to add the number of nanoseconds in this ZonedDateTime and return a copy of ZonedDateTime after addition.This method works on the instant time-line and adding one nanosecond return the time-line of one nanosecond later. Note that this method is a diff
    2 min read
    ZonedDateTime get() method in Java with Examples
    The get() method of ZonedDateTime class in Java is used to get the value of the specified field passed as input from this ZonedDateTime as an integer.This method queries this ZonedDateTime for the value of the field and the returned value will always be within the valid range of values for the field
    2 min read
    ZonedDateTime withHour() method in Java with Examples
    withHour() method of a ZonedDateTime class used to alter hour-of-day in this ZonedDateTime and return a copy of ZonedDateTime after this operation.This method operates on the local time-line, changing the time of the local date-time and after this operation local date-time is converted back to a Zon
    2 min read
    ZonedDateTime minusNanos() method in Java with Examples
    minusNanos() method of a ZonedDateTime class used to subtract the number of nanoseconds from this ZonedDateTime and return a copy of ZonedDateTime after subtraction.This method works on the instant timeline and subtracting one nanosecond return the timeline of one nanosecond earlier. Note that this
    2 min read
    ZonedDateTime minusHours() method in Java with Examples
    minusHours() method of a ZonedDateTime class used to subtract the number of hours from this ZonedDateTime and return a copy of ZonedDateTime after subtraction.This operates on the instant time-line, such that subtracting one hour will always be a duration of one hour earlier. subtracting one hour ma
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences