Wednesday 24 January 2018

How to use ofInstant method of LocalDateTime Class | Java 8 Date and Tim


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

LocalDateTimeDemo.java

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;

public class LocalDateTimeDemo
{

    public static void main(String[] args)
    {

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

        ZoneId zoneId = ZoneId.systemDefault();
        System.out.println("zoneId = "+zoneId);
        /*
         * Parameters:
         *
         * instant - the instant to create the date-time from, not
         * null
         *
         * zone - the time-zone, which may be an offset, not null
         *
         * Returns:the local date-time, not null
         */

        LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, zoneId);
        System.out.println("localDateTime = "+localDateTime);
    }

}

Output

instant = 2018-01-16T04:49:52.570Z
zoneId = Asia/Calcutta
localDateTime = 2018-01-16T10:19:52.570

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

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

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/2732bd5046563d647669928b143687e5dbf4d99f/BasicJava/LocalDateTimeDemo_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