Basit Basit - 1 month ago 41
PHP Question

Firebase timestamp in php

Which method to use in php to generate firebase timestamp, which is equally to firebase.serverValue.timestamp?

I have tried using

time()
, apparently it's wrong format.

Answer
firebase.serverValue.timestamp 

public static final Map TIMESTAMP

A placeholder value for auto-populating the current timestamp (time since the Unix epoch, in milliseconds) by the Firebase Database servers. Doc Link

As it reads in the documentation it's in millis. The actual definition of timestamp is in seconds but, anyway to get the actual timestamp in millis in PHP you have to

microtime();

Edit: to get millis from microseconds (returned by microtime()) you have to:

$timeparts = explode(" ",microtime());
$currenttime = bcadd(($timeparts[0]*1000),bcmul($timeparts[1],1000));
echo $currenttime;