ZonedDateTime format(DateTimeFormatter formatter) example
Description
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;
/*w ww .j a va 2 s . c om*/
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.