how convert servervalue.timestamp simpledateformat("dd mm yyyy") date deprecated not able use , way use calender
you cannot use server.timestamp
date. doc says:
a placeholder value auto-populating current timestamp (time since unix epoch, in milliseconds) determined firebase servers
this means when setvalue()
or updatechildren()
, can put constant in map
tell server put epoch time in node instead. example:
mref = firebasedatabase.getinstance().child("whatever/path/in/your/database"); mref.setvalue( server.timestamp );
this set in <your firebase>/whatever/path/in/your/database
long 149141530600. current epoch time fetched while writing answer. corresponds number of milliseconds passed since january 1st 1970 when copied value. then, if have listener node, can calendar using:
long time = datasnapshot.getvalue(long.class); calendar calendar = gregoriancalendar.getinstance(); calendar.settimeinmillis(time);
if want time server set (saving in database pointless), can use special node:
`firebasedatabase.getinstance().getreference(".info/servertimeoffset");`
a listener node returns double
represents approximative offset between device time , server time. can set calendar
using:
calendar.settimeinmillis(system.currenttimemillis() + offset);
Comments
Post a Comment