0

I need to convert milliseconds to dates times(It depends). For example 14800000 milliseconds (14800 seconds) it becomes

4 hours, 6 minutes - not 4 hours, 6 minutes, 40 seconds

If it's 21 seconds, then you should say only "21 seconds"

I tried it with Datetime, but it never worked. That's why I ask but without DateTime. Thee data that must be: years, months, weeks, days, hours, minutes and seconds (single and plural)

like this code:

$milliseconds = '183547165'; $time = $milliseconds / 1000; $days = floor($time / (24*60*60)); $hours = floor(($time - ($days*24*60*60)) / (60*60)); $minutes = floor(($time - ($days*24*60*60)-($hours*60*60)) / 60); $seconds = ($time - ($days*24*60*60) - ($hours*60*60) - ($minutes*60)) % 60; echo $days.' days<br>'.$hours.' hours<br>'.$minutes.' minutes<br>'.$seconds.' seconds'; ?>

I have a hard time doing that. How do I do it?? Can you help me??

Fedee MC
  • 13
  • 5
  • 2
    so because `DateTime` did not work for you, we cant use it our answer? –  Apr 09 '18 at 02:35
  • 1
    I think OP wants to convert the time to a human readable string. If so, the title and question are quite misleading. – fubar Apr 09 '18 at 02:35
  • You may find it useful to look at `DateTime::diff()` and `DateInterval`. – fubar Apr 09 '18 at 02:50
  • Convert `14800000` to `14800` with mathematics, then use the above closed question to convert to your expected output. – Lawrence Cherone Apr 09 '18 at 03:01

0 Answers0