Monday 12 February 2018

How to use atZoneSameInstant method of OffsetDateTime Class | Java 8 Date and Time


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

OffsetDateTimeDemo.java

import java.time.OffsetDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;

public class OffsetDateTimeDemo
{

    public static void main(String[] args)
    {

        OffsetDateTime offsetDateTime = OffsetDateTime
                .parse("2017-02-03T12:30:30+01:00");
        System.out.println(offsetDateTime);

        ZoneId zoneId = ZoneId.systemDefault();
        System.out.println(zoneId);

        /*
         * Parameters:
         *
         * zone - the time-zone to use, not null
         *
         * Returns:
         *
         * the zoned date-time formed from this date-time, not null
         */

        ZonedDateTime zonedDateTime = offsetDateTime.atZoneSameInstant(zoneId);
        System.out.println(zonedDateTime);

    }

}

Output

2017-02-03T12:30:30+01:00
Asia/Calcutta
2017-02-03T17:00:30+05:30[Asia/Calcutta]

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

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

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