format method

String format(
  1. ZonedDateTime zonedDateTime
)

Formats a ZonedDateTime object according to the pattern.

This method includes timezone information in the output if the pattern contains timezone specifiers (Z, z, X).

Example:

final formatter = DateTimeFormatter.ofPattern('yyyy-MM-dd HH:mm:ss Z');
final zoned = ZonedDateTime.now(ZoneId.of('America/New_York'));
print(formatter.format(zoned)); // 2024-06-27 10:30:45 -0400

final formatterWithName = DateTimeFormatter.ofPattern('EEE, dd MMM yyyy HH:mm:ss zzz');
print(formatterWithName.format(zoned)); // Thu, 27 Jun 2024 10:30:45 EDT

Implementation

String format(ZonedDateTime zonedDateTime) => _format(zonedDateTime.localDateTime, zonedDateTime);