Friday 9 February 2018

How to use equals, isAfter and isBefore methods of OffsetDateTime Class | Java 8 Date and Time


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

OffsetDateTimeDemo.java

import java.time.OffsetDateTime;

public class OffsetDateTimeDemo
{

    public static void main(String[] args)
    {

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

        OffsetDateTime offsetDateTime2 = OffsetDateTime
                .parse("2017-02-03T12:30:30+01:00");
        System.out.println(offsetDateTime2);
        /*
         * Returns:true if this is equal to the other date-time
         */

        System.out.println(offsetDateTime1.equals(offsetDateTime2));

        /*
         * Returns:true if this date-time is after the specified
         * date-time
         */

        System.out.println(offsetDateTime1.isAfter(offsetDateTime2));

        /*
         * Returns:true if this date-time is before the specified
         * date-time
         */


        System.out.println(offsetDateTime1.isBefore(offsetDateTime2));

    }

}

Output

2016-02-03T12:30:30+01:00
2017-02-03T12:30:30+01:00
false
false
true

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

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

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