Clock example in java 8







Clock example in java 8

import java.time.Clock;
import java.time.Instant;
/**
* Clock example in java 8
*/
public class ClockExample {
   public static void main(String[] args) {
       //clock provides date and time using a current time-zone
       Clock clock = Clock.systemDefaultZone();
       System.out.println("clock="+clock);
       System.out.println("current millisecond instant of the clock = "+clock.millis());
       //Instant class is for - instantaneous point on the time-line
       Instant instant = clock.instant();
       System.out.println("instant="+instant);
   }
}
/* OUTPUT
clock=SystemClock[Asia/Calcutta]
current millisecond instant of the clock = 1494600610092
instant=2017-05-12T14:50:10.092Z
*/

Having any doubt? or you you liked the tutorial! Please comment in below section.
Please express your love by liking JavaMadeSoEasy.com (JMSE) on facebook, following on google+ or Twitter.

eEdit
Must read for you :