Saturday, January 2, 2021

Java 8 - Date and Time API

1. Get the Local Date 

package Java8;

import java.time.LocalDate;

public class DateTime {


public static void main(String[] args) {

dateTime dt = new dateTime();

LocalDate date = LocalDate.now();

LocalDate yesterday = date.minusDays(1);

LocalDate tomorrow = yesterday.plusDays(2);

System.out.println("Today date is : " + date);

System.out.println("Yesterday date is : " + yesterday);

System.out.println("Tomorrow date is: " + tomorrow);

}


}


output: 

Today date is: 2021-01-02

Yesterday date is: 2021-01-01

Tomorrow date is: 2021-01-03