Multiplication of Time in PHP

1435288416000 php StackoverFlow

by Start Bootstrap

Today i crossed across a Question about Multiplying a Time using PHP Here’s the Link

After a small research 5 minutes i wrote the answer

Here is what you should do

Step 1 : Convert your hours into seconds

$seconds = strtotime("1970-01-01 $maritime UTC")

Step 2 : Multiply it directly

$multiply = $seconds * 5;

Step 3 : Convert the seconds back to hours, And you’re done !

echo gmdate("d H:i:s",$multiply);

So Your final code shall be

$maritime ='01:10:00';
$seconds = strtotime("1970-01-01 $maritime UTC");
$multiply = $seconds * 5;  #Here you can multiply with your dynamic value
echo gmdate("d H:i:s",$multiply);

And Everything goes, ok.. After few minutes the OP commented me, “If i Multiply 25 times” then he can’t able to get the expected output. When i test i found that the gmdate gives the ouput like 1 day xx hours xx minutes and xx seconds Mean while the User Rizer question me with this link, that the OP seems to get the answer in raw time, Then again i started the research and ended with the code which is made upon DateTime

$maritime ='01:10:00';
$seconds = strtotime("1970-01-01 $maritime UTC");
$multiply = $seconds * 25;  #Here you can multiply with your dynamic value
$seconds = $multiply;
$zero    = new DateTime("@0");
$offset  = new DateTime("@$seconds");
$diff    = $zero->diff($offset);
echo sprintf("%02d:%02d:%02d", $diff->days * 24 + $diff->h, $diff->i, $diff->s);

Here are the Eval Link1 and Link2