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

2
  • 1
    The difference is milliseconds vs seconds. So /1000 Commented Jul 21, 2013 at 17:46
  • possible duplicate of php: convert milliseconds to date Commented Jul 21, 2013 at 17:47

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.