Java - Format a LocalDate, an OffsetDateTime, and ZonedDateTime using ISO_DATE format

Description

Format a LocalDate, an OffsetDateTime, and ZonedDateTime using ISO_DATE format

Demo

import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;

public class Main {
  public static void main(String[] args) {
    String ldStr = DateTimeFormatter.ISO_DATE.format(LocalDate.now());
    String odtStr = DateTimeFormatter.ISO_DATE.format(OffsetDateTime.now());
    String zdtStr = DateTimeFormatter.ISO_DATE.format(ZonedDateTime.now());

    System.out.println("Local Date; " + ldStr);
    System.out.println("Offset Datetime: " + odtStr);
    System.out.println("Zoned Datetime: " + zdtStr);
  }//from w ww . ja v  a  2 s  .c  o  m
}

Result

Related Topic