While writing a doc to the Firestore, I often see that the difference between the serverTimestamp() sentinel and the new Date() object is non-zero. 
The difference ranges between a few seconds to tens of minutes.
Aren't they doing the same thing?

Code for the example in Cloud Functions
docRef.set({
  'date-timestamp': new Date(),
  'server-timestamp': admin.firestore.FieldValue.serverTimestamp(),
}).catch(console.error);
They are not doing the same thing.
serverTimestamp() converts to the date as reckoned by Google servers, at the time the document write was received at the server.
new Date() yields the date as reckoned by the client at the time the Date object was created, regardless of any other factors.
Obviously, in your example, the reckoning of time is different between the client and the server. There will always be some difference, as there is latency between the client and the server that can't be avoided.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With