Monday 19 February 2018

How to use ofInstant method of OffsetTime Class | Java 8 Date and Time


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

OffsetTimeDemo.java

import java.time.Instant;
import java.time.OffsetTime;
import java.time.ZoneId;

public class OffsetTimeDemo
{

    public static void main(String[] args)
    {

        Instant instant = Instant.now();
        System.out.println("instant = " + instant);

        ZoneId zoneId = ZoneId.systemDefault();
        System.out.println("zondId = "+zoneId);

        /*
         * Obtains an instance of OffsetTime from an Instant and zone ID.
         *
         * Parameters:
         *
         * instant - the instant to create the time from, not null
         *
         * zone - the time-zone, which may be an offset, not null
         *
         * Returns:
         *
         * the offset time, not null
         */


        OffsetTime offsetTime = OffsetTime.ofInstant(instant, zoneId);
        System.out.println("offsetTime  = " + offsetTime);

    }

}

Output

instant = 2018-02-04T02:36:47.762Z
zondId = Asia/Calcutta
offsetTime  = 08:06:47.762+05:30

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

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

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/6f1f0d2759f060503c7b9e4a4259ae3ddbfe139e/BasicJava/OffsetTimeDemo_ofInstant/?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