Wednesday 28 March 2018

How to use between method of Period Class | Java 8 Date and Time


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

PeriodDemo.java

import java.time.LocalDate;
import java.time.Month;
import java.time.Period;

public class PeriodDemo
{

    public static void main(String[] args)
    {

        LocalDate startDate = LocalDate.of(2010, Month.JANUARY, 21);
        System.out.println("startDate = " + startDate);

        LocalDate endDate = LocalDate.of(2025, Month.JANUARY, 21);
        System.out.println("endDate = " + endDate);

        /*
         * Parameters:
         *
         * startDateInclusive - the start date, inclusive, not null
         * endDateExclusive - the end date, exclusive, not null
         *
         * Returns:
         *
         * the period between this date and the end date, not null
         */

        Period period = Period.between(startDate, endDate);
        System.out.println("period = " + period);
    }

}

Output

startDate = 2010-01-21
endDate = 2025-01-21
period = P15Y

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

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

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