Wednesday 14 February 2018

How to form OffsetDateTime using atDate method of OffsetTime Class | Java 8 Date and Time


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

OffsetTimeDemo.java

import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.time.OffsetTime;

public class OffsetTimeDemo
{

    public static void main(String[] args)
    {

        OffsetTime offsetTime = OffsetTime.parse("10:30:30+05:30");
        System.out.println("offsetTime = " + offsetTime);

        LocalDate localDate = LocalDate.now();
        System.out.println("localDate = " + localDate);

        /*
         * Combines this time with a date to create an OffsetDateTime.
         *
         * Parameters:
         *
         * date - the date to combine with, not null
         *
         * Returns:
         *
         * the offset date-time formed from this time and the
         * specified date, not null
         */

        OffsetDateTime offsetDateTime = offsetTime.atDate(localDate);
        System.out.println("offsetDateTime = " + offsetDateTime);
    }

}

Output

offsetTime = 10:30:30+05:30
localDate = 2018-01-31
offsetDateTime = 2018-01-31T10:30:30+05:30

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

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

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