Getting server timestamp in firebase 3

4,705 views
Skip to first unread message

Sufiyan Yusuf

unread,
May 19, 2016, 12:37:13 PM5/19/16
to Firebase Google Group
Hi All

How do I get the server timestamp in firebase 3 ?
firebase.ServerValue.TIMESTAMP doesn't work apparently.

Thanks

Don Barthel

unread,
May 19, 2016, 12:51:33 PM5/19/16
to Firebase Google Group
Its now firebase.database.ServerValue.TIMESTAMP

Also check that your calls to .key() are now .key and to .ref() are now .ref.

676...@gmail.com

unread,
May 19, 2016, 4:17:33 PM5/19/16
to Firebase Google Group
I completly cannot understand how you are using this feature.

For example, I'm just pushing some values using POST metod directly from PHP curl to my Firebase account. But what I should do to create another field which will store timestamp based on time readings from Firebase servers? As I understand, I should add new field called something like "timestamp" but what this field shold contain? just firebase.ServerValue.TIMESTAMP and it is will be replaced to timestamp when processed by Firebase?

Michael Bleigh

unread,
May 19, 2016, 4:24:10 PM5/19/16
to Firebase Google Group

If you’re using the REST API you can use the object {".sv": "timestamp"} to insert a timestamp (the object will be turned into an integer by the server).


--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/58070fd6-babe-4888-ae50-24b8a466b120%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

676...@gmail.com

unread,
May 19, 2016, 5:34:31 PM5/19/16
to Firebase Google Group
I'm using this code:

//its a comma separated string with data from my sensor

$pieces = explode(",", $sensor_data);

//splitting string

$data = array(
    's1'      => $pieces[3],
    's2'    => $pieces[0],
    't1'       => $pieces[4],
    't2' => $pieces[6],
    'h1'      => $pieces[5],
'r1'      => $pieces[2],
's1'      => $pieces[1],
'published_at' => $published_at,
'p1'      => $pieces[7],
'timestamp'     => 'WHAT SHOULD BE HERE?',
);

//preparing for curl

$content = json_encode($data);

Now this json package will be pushed into my Firebase. So I just should insert {".sv": "timestamp"} as content of variable and finally server turns it into timestamp?

Joe White

unread,
May 22, 2016, 9:11:21 PM5/22/16
to Firebase Google Group
Shouldn't you be directly putting in the UTC timestamp (available on the client) ... so you have a proper universal time to handle (converting to whatever particular locale a client later for display?

Don Barthel

unread,
May 23, 2016, 2:04:02 AM5/23/16
to Firebase Google Group
I think that you can't rely on all clients having their clocks accurate. If instead each client uses the server's timestamp, then everything is consistent.

Joe White

unread,
May 23, 2016, 4:12:40 PM5/23/16
to Firebase Google Group
SO long as the "server" timestamp is always in UTC without any daylight or timezone modification.  I understand that this is the current state, but I would suggest that this information be explicitly added to the Firebase documentation about "server timestamps".

Thanks!

Jacob Wenger

unread,
May 23, 2016, 5:04:11 PM5/23/16
to fireba...@googlegroups.com
@676...@gmail.com - Yes, just add it as a variable and the Firebase servers will convert it into a timestamp for you.

@Joe - Thanks for the feedback. I will personally make sure the docs get updated to indicate that the generated server timestamp is the current UTC timestamp in milliseconds since the epoch. You should use this instead of relying on clients which may be out-of-date or malicious.

This message (and any associated files) may contain VelociKey confidential and/or privileged information. If you are not the intended recipient or authorized to receive this for the intended recipient, you must not use, copy, disclose or take any action based on this message or any information herein. If you have received this message in error, please advise the sender immediately by sending a reply e-mail and delete this message. Thank you for your cooperation.

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.

Sufiyan Yusuf

unread,
May 24, 2016, 2:11:43 PM5/24/16
to Firebase Google Group
Works perfectly, thanks a lot...

Joe White

unread,
May 25, 2016, 10:51:38 AM5/25/16
to Firebase Google Group
@Jacob Wenger .. great!!  (Some of us "oldsters" here remember teaching folk NOT to use server timestamps on MS SQL Server, Windows Server etc because those timestamps were always local (and sometimes not even in the righe locale because of faulty system admin actions.) Glad to hear that the standard timestamp is the "UTC timestamp" (perhaps that should be tne new name rather than "server timestamp".
Reply all
Reply to author
Forward
0 new messages