I know you can pull the server timestamp in web, ios, and android - but what about the new Cloud Functions for Firebase? I can't figure out how to get the server timestamp there? Use case is me wanting to timestamp an email when it arrives.
On web it is Firebase.database.ServerValue.TIMESTAMP
But that doesn't seem to be available in the functions node server interface?
I think it is late and I may be missing the point here...
EDIT
I am initializing like this
admin.initializeApp(functions.config().firebase); const fb = admin.database()
Then, it is being called like this..
Firebase.database.ServerValue.TIMESTAMP
But, that is from a client side integration. On Functions, Firebase isn't initialized like this. I've tried
admin.database().ServerValue.TIMESTAMP
and
fb.ServerValue.TIMESTAMP
To convert Firebase timestamp to date and time with JavaScript, we use the Date constructor. const timestamp = { nanoseconds: 0, seconds: 1562524200 }; console. log(new Date(timestamp. seconds * 1000));
To reach the timestamp of firebase server on client, you first need to write the value to the server then read the value. firebase. database(). ref('currentTime/').
firestore. Timestamp. A Timestamp represents a point in time independent of any time zone or calendar, represented as seconds and fractions of seconds at nanosecond resolution in UTC Epoch time. It is encoded using the Proleptic Gregorian Calendar which extends the Gregorian calendar backwards to year one.
To convert a Firestore date or timestamp to a JavaScript Date, we use firebase. firestore. Timestamp. fromDate to convert the a date to a Firestore timestamp.
Since you're already using the admin SDK, the correct syntax is:
admin.database.ServerValue.TIMESTAMP
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