Wednesday 14 March 2018

How to use compareTo and equals methods of ZoneOffset Class | Java 8 Date and Time


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

ZoneOffsetDemo.java

import java.time.ZoneOffset;

public class ZoneOffsetDemo
{

    public static void main(String[] args)
    {
        ZoneOffset zoneOffset1 = ZoneOffset.ofHours(2);
        System.out.println("zoneOffset1 = " + zoneOffset1);
        ZoneOffset zoneOffset2 = ZoneOffset.ofHours(1);
        System.out.println("zoneOffset2 = " + zoneOffset2);
        /*
         * Parameters:
         *
         * other - the other date to compare to, not null
         *
         * Returns:
         *
         * the comparator value, negative if less, positive if greater
         */

        int value = zoneOffset1.compareTo(zoneOffset2);
        System.out.println(value);

        /*
         * Parameters:
         *
         * obj - the object to check, null returns false
         *
         * Returns:
         *
         * true if this is equal to the other offset
         */

        boolean isEqual = zoneOffset1.equals(zoneOffset2);
        System.out.println(isEqual);
    }

}

Output

zoneOffset1 = +02:00
zoneOffset2 = +01:00
-3600
false

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

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

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/dc7c5f1cf2584c5bc7f3eb33e62ff414965c0d6f/BasicJava_2018/ZoneOffsetDemo_compareTo_equals/?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