Java - LocalDate

About

java/time/LocalDate - A date in the ISO-8601 calendar system, such as 2007-12-03

  • without a time-zone
  • without the time part (only YYYY-MM-DD) (ie with day precision)

Management

Init

in the default time zone

LocalDate localDate = LocalDate.of(year,month,day);
LocalDate localDate = LocalDate.parse("2009-01-01",DateTimeFormatter.ISO_DATE);
LocalDate localDate = LocalDate.now();

Print

sout(localDate.format(DateTimeFormatter.ISO_DATE));

Between

  • Number of days between two local date
import static java.time.temporal.ChronoUnit.DAYS;
DAYS.between(from,to)

Format

With java/time/format/DateTimeFormatter. Note this is a datetime otherwise

LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd-HHmm"))

note:

  • HH will always output 2 digits whereas H will only output one digit (same for (m and mm)
  • ppH outputs the hour-of-day padded on the left with spaces to a width of 2.

Powered by ComboStrap