Monday 15 January 2018

How to check date is after or before specified date | Java 8 LocalDate Class | Java 8 Date and Time


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

LocalDateDemo.java

import java.time.LocalDate;

public class LocalDateDemo
{

    public static void main(String[] args)
    {
        LocalDate date1 = LocalDate.parse("2018-07-03");
        System.out.println("date1= "+date1);
       
        LocalDate date2 = LocalDate.parse("2017-03-03");
        System.out.println("date2= "+date2);
       
        /*
         * Returns:true if this date is after the specified date
         */

        System.out.println(date1.isAfter(date2));

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

        System.out.println(date1.isBefore(date2));

        /*
         * Returns:true if this date is equal to the specified date
         */

        System.out.println(date1.isEqual(date2));

    }

}

Output

date1= 2018-07-03
date2= 2017-03-03
true
false
false

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

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

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