LocalDateTime yesterday as String - Java java.time

Java examples for java.time:LocalDateTime

Description

LocalDateTime yesterday as String

Demo Code


//package com.java2s;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;

public class Main {
    public static String yesterday(LocalDateTime now) {
        DateTimeFormatter formatter = DateTimeFormatter
                .ofPattern("yyyy-MM-dd");
        return now.minus(1, ChronoUnit.DAYS).withHour(0).withMinute(0)
                .withSecond(0).format(formatter);
    }/*from  w ww  .ja v a 2 s  .c  om*/
}

Related Tutorials