Wednesday 21 February 2018

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


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

ZoneDateTimeDemo.java

import java.time.ZonedDateTime;

public class ZoneDateTimeDemo
{

    public static void main(String[] args)
    {

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

        ZonedDateTime zonedDateTime2 = ZonedDateTime
                .parse("2017-02-03T12:30:30+01:00");
     
        System.out.println(zonedDateTime2);

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

        System.out.println(zonedDateTime1.equals(zonedDateTime2));

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

        System.out.println(zonedDateTime1.isAfter(zonedDateTime2));

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


        System.out.println(zonedDateTime1.isBefore(zonedDateTime2));
    }

}

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/ZoneDateTimeDemo_isafter_before.zip?attredirects=0&d=1

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

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