Server timestamps
📖 Scenario: You are building a simple chat app using Firebase. Each message needs to have a timestamp showing when it was sent. To keep the time consistent for all users, you want to use Firebase's server timestamp feature instead of the user's device time.
🎯 Goal: Create a Firebase Firestore document for a chat message that includes a server-generated timestamp.
📋 What You'll Learn
Create a dictionary called
message with a text field set to 'Hello, Firebase!'.Add a field called
timestamp using Firebase's server timestamp placeholder.Write code to add the
message dictionary to a Firestore collection called messages.Ensure the timestamp uses Firebase's server time, not the client device time.
💡 Why This Matters
🌍 Real World
Using server timestamps ensures all chat messages have consistent and trustworthy time data regardless of user device clocks.
💼 Career
Understanding server timestamps is essential for backend consistency in cloud applications, especially in real-time databases and messaging apps.
Progress0 / 4 steps