PreciseDateTime.fromMicrosecondsSinceEpoch constructor

PreciseDateTime.fromMicrosecondsSinceEpoch(
  1. int microsecondsSinceEpoch
)

Constructs a new PreciseDateTime instance with the given microsecondsSinceEpoch.

The constructed DateTime represents 1970-01-01T00:00:00Z + microsecondsSinceEpoch us in the given time zone (local or UTC).

final newYearsEve =
    PreciseDateTime.fromMicrosecondsSinceEpoch(1640901600000000);
print(newYearsEve); // 2021-12-31 19:30:00.000Z

Implementation

PreciseDateTime.fromMicrosecondsSinceEpoch(int microsecondsSinceEpoch)
  : microsecond = microsecondsSinceEpoch % 1000,
    super(
      DateTime.fromMillisecondsSinceEpoch(
        (microsecondsSinceEpoch / 1000).floor(),
        isUtc: true,
      ),
    );