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:
Clock system() Method in Java with Examples
Next article icon

Clock system() Method in Java with Examples

Last Updated : 17 Jan, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

java.time.Clock.system(ZoneId zone) method is a static method of Clock class which returns a clock that returns the current instant of the clock using best available system clock with ZoneID of the returned clock is set to the ZoneID passed. This method can use System.currentTimeMillis(), or other higher resolution clock if the clock is available to use. At the time of conversion from instant to date or time, the specified time-zone is used to give date and time of that timezone. Returned clock from this method is immutable, thread-safe and Serializable. 

Syntax:

public static Clock system(ZoneId zone)

Parameters: This method takes a mandatory parameter zone which is the time-zone to use at time of conversion of the instant to date-time Returns: The method returns Clock object for the given ZoneId Example:

Code: // create a Zone Id for Europe/Paris ZoneId zoneId = ZoneId.of("Europe/Paris");  // base Clock with default zone Clock realClock=Clock.system(zoneId); System.out.println(clock.instant());  Output::  2018-08-21T10:25:52.361Z  Explanation::  when you call system(ZoneId) for Clock then the system(ZoneId) method will return a Class Object for the given ZoneId.you can get date and time of clock by using instant of class.

Below programs illustrates system(ZoneId) method of java.time.Clock class: Program 1: When Clock is created with system(ZoneId) where ZoneId is "Europe/Paris" and print date and time of clock. 

Java
// Java program to demonstrate // system(ZoneId) method of Clock class  import java.time.Clock; import java.time.Instant; import java.time.ZoneId; import java.time.ZonedDateTime;  /**  * Demonstrates the use of the system(ZoneId) method of Clock class  */ public class SystemMethodDemo {      public static void main(String[] args) {         // create a ZoneId for Europe/Paris         ZoneId zoneId = ZoneId.of("Europe/Paris");          // create Clock with system(zoneId) method         Clock clock = Clock.system(zoneId);          // Get instant of class         Instant instant = clock.instant();          // Get ZonedDateTime object from instantObj to get date time         ZonedDateTime time = instant.atZone(clock.getZone());          // Print details of time         System.out.println("Instant for class is " + time);     } } 
Output:
Instant for class is 2018-08-22T13:53:35.779+02:00[Europe/Paris]

Program 2: Create Clock with Zone "US/Arizona" using system() and print the zoneId using getZone(). 

Java
// Java program to demonstrate // system(ZoneId) method of Clock class  import java.time.*;  /**  * This class demonstrates the Clock class's system() method,  * which allows us to create a clock that represents the current time  * in a particular time zone  */ public class SystemMethodDemo {      public static void main(String[] args) {          // Create a ZoneId for US/Arizona         ZoneId zoneId = ZoneId.of("US/Arizona");          // Create a Clock instance with the system(zoneId) method         Clock clock = Clock.system(zoneId);          // Print details of the ZoneId of the new Clock         System.out.println("ZoneID of class is " + clock.getZone());     } } 
Output:
ZoneID of class is US/Arizona

Reference: https://docs.oracle.com/javase/8/docs/api/java/time/Clock.html#system-java.time.ZoneId-


Next Article
Clock system() Method in Java with Examples

A

AmanSingh2210
Improve
Article Tags :
  • Java
  • java-basics
  • Java-lang package
  • Java-Functions
  • Java-time package
  • Java-Clock
Practice Tags :
  • Java

Similar Reads

    Clock systemUTC() Method in Java with Examples
    java.time.Clock.systemUTC() method is a static method of Clock class which returns a clock that returns the current instant of the clock using the best available system clock where Zone of the returned clock is UTC time-zone. When the current instant is needed without the date or time, then use syst
    2 min read
    Clock tick() Method in Java with Examples
    tick(Clock baseClock, Duration tickDuration) method of java.time.Clock is a static method of Clock class that returns a clock that returns instants from the base clock rounded to the nearest occurrence of the specified duration in the parameter. The specified base clock duration must be positive, ne
    4 min read
    Clock tickSeconds() method in Java with Examples
    java.time.Clock.tickSeconds(ZoneId zone) method is a static method of Clock class that returns a clock that returns the current instant ticking in whole Seconds using the best available system clock and zone of instant is same as the instant passed as a parameter. The returned clock is also immutabl
    2 min read
    Java 8 Clock offset() method with Examples
    Java Clock class is part of Date Time API, java.time.Clock, of Java. The Java Date Time API was added from Java version 8. The offset() method is a static method of Clock class which returns a clock with instant equal to the sum of the instants of clock passed as parameter and specific Offset durati
    3 min read
    Java 8 Clock instant() method with Examples
    Java Clock class is part of Date Time API, java.time.Clock, of Java. The Java Date Time API was added from Java version 8. instant() method of Clock class returns a current instant of Clock object as Instant Class Object. Instant generates a timestamp to represent machine time. So this method genera
    3 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