Monday 12 February 2018

How to get current date and time using now methods of OffsetDateTime Class


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

OffsetDateTimeDemo.java

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

public class OffsetDateTimeDemo
{

    public static void main(String[] args)
    {

        Clock clock = Clock.systemUTC();
        System.out.println(clock);
       
        /*
         * Parameters:
         *
         * clock - the clock to use, not null
         *
         * Returns:the current date-time, not null
         */

        OffsetDateTime offsetDateTime1 = OffsetDateTime.now(clock);
        System.out.println(offsetDateTime1);
       
        ZoneId zoneId = ZoneId.systemDefault();
        System.out.println(zoneId);
       
        /*
         * Parameters:
         *
         * zone - the zone ID to use, not null
         *
         * Returns:the current date-time using the system clock, not
         * null
         */

        OffsetDateTime offsetDateTime2 = OffsetDateTime.now(zoneId);
        System.out.println(offsetDateTime2);

    }

}

Output

SystemClock[Z]
2018-01-29T03:53:50.554Z
Asia/Calcutta
2018-01-29T09:24:15.069+05:30

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

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

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/572947048c5892379e75d8e421fa231c20e2d3bc/BasicJava/OffsetDateTimeDemo_now_methods/?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