ServerValue.TIMESTAMP with Firebase

1,415 views
Skip to first unread message

muhannd dhahier

unread,
May 14, 2017, 6:46:12 PM5/14/17
to Firebase Google Group

I used ServerValue.TIMESTAMP to save the time in Firebase DB.

My code is

myRef.child(idna).child("msg_time").setValue(ServerValue.TIMESTAMP);

The value will be "msg_time": 1494779954547

First- Is it a correct way to save the time in Firebase ?

Second- How to convert it to readable date like dd-MM-yyyy HH:mm:ss

I tried:

Long timestamp =1494779904394;

SimpleDateFormat sfd = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
sfd.format(new Date(timestamp));

but it said Integer number too big.

any idea?

Michael Bleigh

unread,
May 15, 2017, 1:20:48 AM5/15/17
to Firebase Google Group

Firebase server timestamps are in milliseconds since epoch. You may need to divide by 1000 to get an accurate time if you aren't working with JavaScript.


--
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/30575b2d-6e67-434e-be1c-e4c71dc63a14%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

JohnReese

unread,
Sep 25, 2018, 12:27:39 PM9/25/18
to Firebase Google Group
You can do this

let date = new Date(this.eventDocAdded.seconds);
console.log(date);


Then date.getMonth, full year, date, day, hours, and time in javascript. Look up date objects :)
Reply all
Reply to author
Forward
0 new messages