Java DateTimeFormatter ISO_DATE format LocalDate, OffsetDateTime, ZonedDateTime

Description

Java DateTimeFormatter ISO_DATE format LocalDate, OffsetDateTime, ZonedDateTime


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  ww  w .  ja  v  a2  s  .  com
}



PreviousNext

Related