Timestamp.fromDateTime constructor

Timestamp.fromDateTime(
  1. DateTime dateTime
)

Creates a new Timestamp instance from the given date.

Timestamp has no timezone/offset to UTC information so you don't need to convert dateTime to UTC.

i.e.

Timestamp.fromDateTime(dateTime);

and

Timestamp.fromDateTime(dateTime.toUtc());

gives the same result.

Implementation

factory Timestamp.fromDateTime(DateTime dateTime) {
  final seconds = (dateTime.millisecondsSinceEpoch / 1000).floor();
  final nanoseconds = (dateTime.microsecondsSinceEpoch % 1000000) * 1000;
  return Timestamp(seconds, nanoseconds);
}