Skip to content

Using serverTimestamp() in Firestore

Sometimes it’s useful to add a timestamp to documents in Firestore, so they can be ordered later.

For that, prefer using serverTimestamp().

This always uses the UTC time standard, and is more reliable that using DateTime.now() on the client.


In your serialization code, you can then use Timestamp.toDate() and Timestamp.fromDate() to get the corresponding DateTime.

Note that two snapshots will be emitted:
- immediately with a null timestamp
- again with a non-null timestamp once the document is written to the server

Previous Next
The Accessibility Tools package Using context.mounted in Flutter 3.7

Last update: 18 septembre 2023
Created: 18 septembre 2023