Java LocalDateTime minus days

Description

Java LocalDateTime minus days


import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;

public class Main {
  public static void main(String[] args) {
    LocalDateTime now = LocalDateTime.now();

    // Get the date time 4 days ago
    LocalDateTime ldt2 = now.minus(4, ChronoUnit.DAYS);

    // Use the minusDays() method to get the same result
    LocalDateTime ldt3 = now.minusDays(4);
    System.out.println("Current Datetime: " + now);
    System.out.println("4 days ago: " + ldt2);
    System.out.println("4 days ago: " + ldt3);
  }/*from  w  w  w  . j  a v a2  s. c o m*/
}



PreviousNext

Related