Reputation: 65
Hi I am trying to take a total amount of seconds i.e. 972 seconds and convert it into this format:
minutes:seconds:milliseconds
I can't find a PHP function such as gmdate() for time that will help me convert it. Please help!
Thank You.
Upvotes: 4
Views: 11489
Reputation: 23562
This works for PHP 5 >= 5.3.0
$date = DateTime::createFromFormat('U.u', microtime(TRUE));
var_dump($date->format('Y-m-d H:i:s.u'));
From DateTime with microseconds
Manual: http://php.net/manual/de/datetime.createfromformat.php
Upvotes: 4
Reputation: 258
Try This
$second = "123456789"
$s = $second%60;
$m = floor(($second%3600)/60);
$h = floor(($second%86400)/3600);
$d = floor(($second%2592000)/86400);
$M = floor($second/2592000);
echo "$M months, $d days, $h hours, $m minutes, $s seconds";
Upvotes: 1
Reputation: 76
In the: http://php.net/manual/en/function.date.php you can use the format: date("i:s:u"); in PHP > 5.2.2,
i: minutes, s:seconds, u:microseconds and use a timestamp in the second argument to set as you were saying 972 seconds -> 0:972:0 But if you only want milliseconds I think you would have to manipulate the resultating string with substr,...
Upvotes: 1