Java Date Time - ZonedDateTime format(DateTimeFormatter formatter) example








ZonedDateTime format(DateTimeFormatter formatter) formats this date-time using the specified formatter.

Syntax

format has the following syntax.

public String format(DateTimeFormatter formatter)

Example

The following example shows how to use format.

import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
//from ww w .j  a  v  a2  s .  c o  m
public class Main {
  public static void main(String[] args) {
    ZonedDateTime dateTime =ZonedDateTime.from(ZonedDateTime.now());
    String s = dateTime.format(DateTimeFormatter.ISO_DATE_TIME);
    System.out.println(s);
  } 
}

The code above generates the following result.