CodesJava

Easy learning with example program codes

Java Clock class


The java.time.Clock class providing access to the current instant, date and time using a time-zone.

Java Clock class methods

Method Description
abstract ZoneId getZone() It is used to get the time-zone being used to create dates and times.
abstract Instant instant() It is used to get the current instant of the clock.
static Clock offset(Clock baseClock, Duration offsetDuration) It is used to obtain a clock that returns instants from the specified clock with the specified duration added
static Clock systemDefaultZone() It is used to obtain a clock that returns the current instant using the best available system clock, converting to date and time using the default time-zone.
static Clock systemUTC() It is used to obtain a clock that returns the current instant using the best available system clock, converting to date and time using the UTC time zone.

Example

package com.codesjava;
 
import java.time.Clock;
 
public class TestExample {
	public static void main(String args[]){
		 Clock clock = Clock.systemDefaultZone();      
		 System.out.println(clock.getZone());  
		 System.out.println(clock.instant());    
	}  
}

Output

Asia/Calcutta
2018-04-15T13:35:48.393Z
Posted in Date   


Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at hr@codesjava.com.

Development

We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on hr@codesjava.com.

Copyright © 2019 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki