Q:

Write a PHP script to convert seconds into days, hours, minutes and seconds

0

Write a PHP script to convert seconds into days, hours, minutes and seconds.

Sample seconds : 200000

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

<?php
function convert_seconds($seconds) 
 {
  $dt1 = new DateTime("@0");
  $dt2 = new DateTime("@$seconds");
  return $dt1->diff($dt2)->format('%a days, %h hours, %i minutes and %s seconds');
  }
echo convert_seconds(200000)."\n";
?>

Sample Output:

2 days, 7 hours, 33 minutes and 20 seconds

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now