Wednesday, 14 February 2018

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


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

OffsetTimeDemo.java

import java.time.OffsetTime;

public class OffsetTimeDemo
{

    public static void main(String[] args)
    {

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

        OffsetTime offsetTime2 = OffsetTime.parse("12:30:30+05:30");
        System.out.println("offsetTime2 = " + offsetTime2);

        /*
         * Returns:true if this is equal to the other time
         */

        System.out.println(offsetTime1.equals(offsetTime2));

        /*
         * Returns:true if this is after the instant of the specified
         * time
         */

        System.out.println(offsetTime1.isAfter(offsetTime2));

        /*
         * Returns:true if this is before the instant of the specified
         * time
         */


        System.out.println(offsetTime1.isBefore(offsetTime2));

    }

}

Output

offsetTime1 = 10:30:30+05:30
offsetTime2 = 12:30:30+05:30
false
false
true

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

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

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