Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the server timestamp in Cloud Functions for Firebase?

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 
like image 471
Justin Handley Avatar asked Apr 23 '17 04:04

Justin Handley


People also ask

How do I display Firebase 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));

How do I find my Firebase server date?

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/').

What is Firebase timestamp?

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.

How do I get the date from firestore timestamp?

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.


1 Answers

Since you're already using the admin SDK, the correct syntax is:

admin.database.ServerValue.TIMESTAMP 
like image 164
Frank van Puffelen Avatar answered Sep 28 '22 04:09

Frank van Puffelen