1

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

laalto
  • 150,114
  • 66
  • 286
  • 303
Dhiral Pandya
  • 10,311
  • 4
  • 47
  • 47
  • 1
    The difference is milliseconds vs seconds. So `/1000` – PeeHaa Jul 21 '13 at 17:46
  • possible duplicate of [php: convert milliseconds to date](http://stackoverflow.com/questions/557959/php-convert-milliseconds-to-date) – PeeHaa Jul 21 '13 at 17:47

2 Answers2

5

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.

srain
  • 8,944
  • 6
  • 30
  • 42
1

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.

tomrozb
  • 25,773
  • 31
  • 101
  • 122
Kman
  • 11
  • 1