2

My server send file last update time as php time() string

my android app receive response from server as php timestamp like 1365228375

as i know android read timestamp in milliseconds

my question is how to convert the php time() to android timestamp and how i can convert the converted timestamp to human readable in android app ?

3
  • If you use time(), converting makes no sense imo. See this to get the time in real ms Commented Apr 6, 2013 at 19:16
  • Hi Jack, if you found an answer useful enough to solve your problem, it would be good to tick it as the answer so that future users can see which solution to work from. Commented Apr 7, 2013 at 1:40
  • No worries mate! it's why we hang around here Commented Apr 7, 2013 at 12:14

3 Answers 3

4

Use Java's Calendar: (since my beloved Date is deprecated) Calendar API

Try something like:

Calendar c = Calendar.getInstance();

c.setTimeInMillis(1365228375*1000);

System.out.print(c.toString()); - just to demonstrate the API has lots of info about presentation

Just put whatever is being returned from your PHP to the Android app in place of the '1365228375' shown above.

Cheers.

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

Comments

2

Well, conversion from seconds to microseconds shouldn't be too difficult;

echo time() * 1000;

If you need the time stamp to be acurate in milliseconds, look at microtime() however, this function does not return an integer so you'll have to do some conversions

Don't know how to convert that to a readable time in Android

Comments

2

There isn't really an "Android" time stamp per se. PHP:time() returns a unix time stamp measured in seconds from epoch GMT/UTC. If you want to create a human readable time stamp such as January 1 1970 00:00:00 GMT you can use Java's Calender but I would recommend using Joda Time instead as it's a lot easier to use and far more robust.

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.