Java Local Date Time

From Chorke Wiki
Revision as of 18:08, 1 February 2024 by Shahed (talk | contribs) (→‎References)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;

class Playground {
    public static void main(String[] args) {
        DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
        LocalDateTime    endDate = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS).plusHours(23).minusNanos(1L);
        LocalDateTime  startDate = endDate.minusDays(1).plusNanos(1L);

        System.out.println("Start Date: " + startDate.format(format));
        System.out.println("end   Date: " +   endDate.format(format));
    }
}

References