Wednesday 28 February 2018

How to use tickSeconds method of Clock class | Java 8 Date and Time


Click here to watch on Youtube : 
https://www.youtube.com/watch?v=_MTT2I2Jouk&list=UUhwKlOVR041tngjerWxVccw

ClockDemo.java

import java.time.Clock;
import java.time.ZoneId;

public class ClockDemo
{

    public static void main(String[] args)
    {
        Clock clock1 = Clock.systemDefaultZone();
        System.out.println("clock1 = " + clock1.instant());

        /*
         * Parameters:
         *
         * zone - the time-zone to use to convert the instant to
         * date-time, not null
         *
         * Returns:
         *
         * a clock that ticks in whole seconds using the specified
         * zone, not null
         */

        Clock clock2 = Clock.tickSeconds(ZoneId.systemDefault());
        System.out.println("clock2 = " + clock2.instant());
    }

}

Output

clock1 = 2018-02-13T04:12:24.569Z
clock2 = 2018-02-13T04:12:40Z

Click the below link to download the code:
https://sites.google.com/site/ramj2eev1/home/javabasics/ClockDemo_tickseconds.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/ClockDemo_tickseconds

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/f479c67d9d2a797db17daef3132e32f3fda78b25/BasicJava/ClockDemo_tickseconds/?at=master

See also:
  • All JavaEE Videos Playlist
  • All JavaEE Videos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Kids Tutorial
  • No comments:

    Post a Comment