Wednesday 11 April 2018

How to use adjustInto method of Instant class | Java 8 Date and Time


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

InstantDemo.java

import java.time.Instant;
import java.time.ZonedDateTime;
import java.time.temporal.Temporal;

public class InstantDemo
{
    public static void main(String[] args)
    {

        Instant instant = Instant.parse("2017-12-03T10:15:30.00Z");
        System.out.println("instant = "+instant);
       
        ZonedDateTime zonedDateTime = ZonedDateTime.now();
        System.out.println("zonedDateTime = "+zonedDateTime);
        /*
         * Parameters:
         *
         * temporal - the target object to be adjusted, not null
         *
         * Returns:
         *
         * the adjusted object, not null
         */

        Temporal temporal = instant.adjustInto(zonedDateTime);
        System.out.println("temporal = "+temporal);

    }

}

Output

instant = 2017-12-03T10:15:30Z
zonedDateTime = 2018-03-31T11:02:53.706+05:30[Asia/Calcutta]
temporal = 2017-12-03T15:45:30+05:30[Asia/Calcutta]

Click the below link to download the code:
https://sites.google.com/site/ramj2eev2/java_basics/InstantDemo_adjustInto.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava_2018/InstantDemo_adjustInto

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/dce3f55388a87b7da919bb2501377068a8838f7f/BasicJava_2018/InstantDemo_adjustInto/?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
  • Cooking Tutorial
  • No comments:

    Post a Comment