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

Blog Search
  • Sysaxiom (4)
  • Github (8)
  • Windows (1)
  • php (25)
  • General Tips (0)
  • GoogleMaps (2)
  • Google App Script (1)
  • Heroku (4)
  • Laravel Middleware (1)
  • xampp (1)
  • Terminal (1)
  • TechCrunch (1)
  • Ubuntu (3)
  • MySQL (2)
Side Widget
can put anything you want inside of these side widgets. They are easy to use, and feature the new Bootstrap 4 card containers!