from google.cloud import firestore
from datetime import datetime
# Create a Firestore client
db = firestore.Client()
# Current timestamp
timestamp = datetime.now()
# Store the timestamp in a document
doc_ref = db.collection('your_collection').document('your_document')
doc_ref.set({
'timestamp_field': timestamp
})
# Retrieve the timestamp from the document
result = doc_ref.get()
stored_timestamp = result.to_dict()['timestamp_field']
# Format the timestamp as a string
formatted_timestamp = stored_timestamp.strftime("%Y-%m-%d %H:%M:%S")
print("Stored timestamp:", formatted_timestamp)