For Firestore Database Server timestamp, use firebase_admin.firestore.SERVER_TIMESTAMP
For local timestamp, use datetime.datetime.now()
(assuming your local machine/server is setup with UTC timezone) or datetime.datetime.utcnow()
.
import datetime# from google.cloud.firestore_v1 import SERVER_TIMESTAMP# from google.cloud.firestore import SERVER_TIMESTAMPfrom firebase_admin.firestore import SERVER_TIMESTAMPdoc_ref = db.collection('test').document()doc_ref.set({ 'created': SERVER_TIMESTAMP, 'local_created': datetime.datetime.now(), 'name': 'Test' })
NOTE: Kotlin have a special Timestamp
class for Firestore timestamp, but datetime
module is sufficient for Python.
NOTE: Refer Setup Firestore on Cloud Functions (Python) for db
instance.