Java Date Time - ZonedDateTime format(DateTimeFormatter formatter) example

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


format has the following syntax.

public String format(DateTimeFormatter formatter)


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(;
    String s = dateTime.format(DateTimeFormatter.ISO_DATE_TIME);

The code above generates the following result.