Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

firebase.database.ServerValue.TIMESTAMP return an Object

I'm working on a web project with Firebase. I call:

firebase.database.ServerValue.TIMESTAMP

and it returns:

{.sv: "timestamp"}

How will I get time of Firebase server with javascript?

like image 792
mutlucan96 Avatar asked Oct 24 '16 09:10

mutlucan96


People also ask

What is ServerValue timestamp?

ServerValue. TIMESTAMP returns a non-null Object and is a placeholder value for auto-populating the current timestamp. It doesn't contain the actual timestamp. The database will replace this placeholder when it will execute the command. It works as you expect when you are using it inside a database.

What is the format of firestore timestamp?

Date and time in the Firestore are saved in their proprietary date format — called Timestamp. Firestore timestamp is just a simple object with two properties — seconds and nanoseconds, which apparently has some advantages over “classic” date format.

How do I get firebase time?

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?

What is timestamp in firebase? 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.


2 Answers

This is what I had to do:

firebase.firestore.FieldValue.serverTimestamp()

Source:

https://firebase.google.com/docs/reference/js/firebase.firestore.FieldValue

like image 124
redolent Avatar answered Sep 22 '22 17:09

redolent


Just to add some more to answer from @cartant:

admin.database.ServerValue.TIMESTAMP returns a non-null Object and is a placeholder value for auto-populating the current timestamp. It doesn't contain the actual timestamp. The database will replace this placeholder when it will execute the command.

It works as you expect when you are using it inside a database.ref but outside of it is just an useless Object.

See this SO Answer for more.

like image 22
Spiral Out Avatar answered Sep 21 '22 17:09

Spiral Out