-1

I have an xml file where the date stored in this format:

<timer>4742086</timer> <- this is not in seconds!

My php process this value to a variable named $timer

This value is a countdown timer (I think its in epoch format)

The problem with this its just a string. I don't have any idea how to convert it to a format like

2 hour 20 minutes 30 seconds remaining

Gable
  • 43
  • 5
  • http://stackoverflow.com/a/7720239/999617 – Vincent Decaux May 30 '14 at 14:40
  • basic math: 60 seconds = 1 minute, 60 minutes = 1 hour, 24 hours = 1 day, etc... And it's not in Epoch format, because 4742086 is Feb 24, 1970. Not exactly something you need to be counting down for anymore. – Marc B May 30 '14 at 14:41
  • `$timer = 4742086; print ("$timer
    "); $hrs = floor($timer / 3600); $mns = floor(($timer - ($hrs*3600)) / 60); $scs = floor($timer % 60); echo $hrs.':'.$mns.':'.$scs;` But this will show `1317:14:46` and this can not be more that 3 hours @MarcB
    – Gable May 30 '14 at 14:54

1 Answers1

0

You'll want: http://php.net/manual/en/function.date.php I believe date('Y-m-d H:i:s', $timer); will do the trick?

l0gic
  • 117
  • 5
  • no, because 4742086 coresponds to Feb 24, 1970. A countdown for that date seems rather... redundant. – Marc B May 30 '14 at 14:42
  • `$timer = 4742086; $timer = time() + $timer; echo date('Y-m-d H:i:s', $timer);` Now it's in the future! Edit: That makes "2014-07-24 14:01:16" – l0gic May 30 '14 at 14:47
  • @l0gic This is not working for me also I want to "show" its: X hours Y minutes Z seconds But thanks for your solution – Gable May 30 '14 at 15:02