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 ?

Noob
  • 2,857
  • 6
  • 33
  • 47
  • If you use `time()`, converting makes no sense imo. See [this](http://stackoverflow.com/questions/3656713/how-to-get-current-time-in-milliseconds-in-php) to get the time in real ms – kero Apr 06 '13 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. – d'alar'cop Apr 07 '13 at 01:40
  • No worries mate! it's why we hang around here – d'alar'cop Apr 07 '13 at 12:14

3 Answers3

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.

Community
  • 1
  • 1
d'alar'cop
  • 2,357
  • 1
  • 14
  • 18
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

thaJeztah
  • 27,738
  • 9
  • 73
  • 92
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.

TJ Thind
  • 784
  • 5
  • 17