Friday 12 January 2018

How to add days and minus days from the today date | Java 8 LocalDate Class | Java 8 Date and Time


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

LocalDateDemo.java

import java.time.LocalDate;

public class LocalDateDemo
{

    public static void main(String[] args)
    {
        /*
         * Returns:the current date using the system clock and default
         * time-zone, not null
         */

        LocalDate todayDate = LocalDate.now();
        System.out.println("Today date = " + todayDate);

        /*
         * Parameters:
         *
         * daysToSubtract - the days to subtract, may be negative
         *
         * Returns:a LocalDate based on this date with the days
         * subtracted, not null
         */

        LocalDate yesterdayDate = todayDate.minusDays(1);
        System.out.println("Yesterday date = " + yesterdayDate);

        /*
         * Parameters:
         *
         * daysToAdd - the days to add, may be negative
         *
         * Returns:a LocalDate based on this date with the days added,
         * not null
         *
         */

        LocalDate tomorrowDate = todayDate.plusDays(1);
        System.out.println("Tommorow date = " + tomorrowDate);
    }

}


Output

Today date = 2018-01-03
Yesterday date = 2018-01-02
Tommorow date = 2018-01-04

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

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

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