difference method

  1. @useResult
Duration difference(
  1. ZonedDateTime other
)

Returns the difference in exact microseconds between this and other.

This function is affected by DST if this and other are across DST transitions.

// DST occurs at 2023-03-12 02:00
// https://www.timeanddate.com/time/change/usa/detroit?year=2023

final winter = ZonedDateTime('America/Detroit', 2023, 3, 12);
final summer = ZonedDateTime('America/Detroit', 2023, 3, 13);

print(summer.difference(winter)); // 23:00:00.000000
print(winter.difference(summer)); // -23:00:00.000000

Implementation

@useResult Duration difference(ZonedDateTime other) => Duration(microseconds: epochMicroseconds - other.epochMicroseconds);