toString method

  1. @override
String toString()
override

Returns the ISO 8601 string representation with timezone information.

The format is: yyyy-MM-ddTHH:mm:ss±HH:mm[ZoneId]

Example:

final zoned = ZonedDateTime.of(
  LocalDateTime.of(2023, 12, 25, 15, 30, 45),
  ZoneId.of('America/New_York')
);

print(zoned.toString()); 
// Output: 2023-12-25T15:30:45-05:00[America/New_York]

Implementation

@override
String toString() {
  final offsetStr = _formatOffset(_offset);
  return '$_localDateTime$offsetStr[${_zone.id}]';
}