Reputation: 10619
I am getting timestamp (1370956788472) of my android message like this :
cursor.getString(cursor.getColumnIndex("date"))
And trying to convert this android timestamp using php date() function and I am getting wrong Date and Time
echo date('Y-m-d H:i:s','1370956788472');
Output : 1997-04-28 09:50:48
But It will display correct date and time if i remove last three character from timestamp (removed 472 from 1370956788472) :
echo date('Y-m-d H:i:s','1370956788');
output: 2013-06-11 13:19:48
What is wrong here and what should i do can I divide my android timestamp with 1000
Upvotes: 1
Views: 1092
Reputation: 11
Don't forget to also adj by the host time aka webserver or localhost if your time is off.
For example my localhost server for developement is off by 25200 so it is
$myTime = time() - 25200;// to get the real time.
$phonetime = ($androidTime/1000) - 25200;
echo $phonetime;
Do if your time is off by hours or a day try adjusting and ever hr = 3600
. So my 25200 is 7 hrs offset.
Upvotes: 1
Reputation: 9082
This time format 1370956788472
(the longer) is in milliseconds.
The shorter one 1370956788
is in seconds, we can get this type time by $time = time()
in php.
so just divide 1000.
Upvotes: 5