Timestamp class

A Timestamp represents a point in time independent of any time zone or calendar, represented as seconds and fractions of seconds at nanosecond resolution in UTC Epoch time. It is encoded using the Proleptic Gregorian Calendar which extends the Gregorian calendar backwards to year one. It is encoded assuming all minutes are 60 seconds long, i.e. leap seconds are 'smeared' so that no leap second table is needed for interpretation. Range is from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. By restricting to that range, we ensure that we can convert to and from RFC 3339 date strings.

see The reference timestamp definition

A snapshot returns a Timestamp for every timestamp field, also through DocumentSnapshot.getTimestamp (or getDate for a DateTime). You can write either a Timestamp or a DateTime.

await firestore.doc('events/launch').set(<String, Object?>{
  'at': Timestamp.fromDate(DateTime.utc(2026, 11, 15, 9)),
});
final DocumentSnapshot<Map<String, Object?>> snapshot =
    await firestore.doc('events/launch').get();
final DateTime? at = (snapshot.get('at') as Timestamp?)?.toDate();

The backend stores microseconds: a write drops the nanoseconds below one microsecond, and the local cache does the same at once, so a value read back can differ from the one written. Timestamps are ordered in time and are equal when seconds and nanoseconds are equal.

Implemented types

Constructors

Timestamp(int seconds, int nanoseconds)
Creates a timestamp from seconds since the Unix epoch (UTC) and a non-negative nanoseconds fraction below one second.
const
Timestamp.fromDate(DateTime date)
Creates a new timestamp from date, with microsecond precision (the precision of DateTime on the Dart VM, and of the Firestore backend).
factory
Timestamp.fromJson(Map<String, Object?> json)
Builds a timestamp from a JSON map created by toJson.
factory
Timestamp.fromMicrosecondsSinceEpoch(int microseconds)
Creates a timestamp from a number of microseconds since the epoch, 1970-01-01T00:00:00Z (negative for earlier instants). Throws an ArgumentError outside the range of Timestamp.
factory
Timestamp.fromMillisecondsSinceEpoch(int milliseconds)
Creates a new timestamp from the given number of milliseconds since the Unix epoch 1970-01-01T00:00:00Z.
factory
Timestamp.now()
Creates a new timestamp with the current date, with millisecond precision.
factory

Properties

hashCode → int
The hash code for this object.
no setteroverride
microsecondsSinceEpoch → int
The number of microseconds since the epoch, 1970-01-01T00:00:00Z (the nanoseconds are truncated). The name of DateTime.microsecondsSinceEpoch and FlutterFire.
no setter
millisecondsSinceEpoch → int
The number of milliseconds since the epoch, 1970-01-01T00:00:00Z (the nanoseconds are truncated). The name of DateTime.millisecondsSinceEpoch and FlutterFire.
no setter
nanoseconds → int
The fraction of a second, in nanoseconds, from 0 to 999,999,999. Always counted forward in time, also for timestamps before the epoch.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
seconds → int
Seconds of UTC time since the Unix epoch, 1970-01-01T00:00:00Z.
final

Methods

compareTo(Timestamp other) → int
Compares this object to another object.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDate() → DateTime
Converts this timestamp to a DateTime in the local time zone, with microsecond precision. Sub-microsecond precision is truncated toward the earlier time.
toJson() → Map<String, Object>
A JSON-serializable representation of this timestamp, in the same shape as the JS SDK's Timestamp.toJSON(). Read it back with Timestamp.fromJson.
toString() → String
A string with the seconds and the nanoseconds of this timestamp, Timestamp(seconds=1, nanoseconds=2), as in the JS and Android SDKs. It is meant for logs and messages; use seconds and nanoseconds, or toDate, to read the value.
override

Operators

operator ==(Object other) → bool
The equality operator.
override

Constants

jsonType → const String
The value of the type field written by toJson.