Multiplication of a time in PHP -


i need multiplication of time in php

$maritime ='01:10:00';        

i need increment $maritime in 5
want answer

01:10:00*5 =  05:50:00 

here should

step 1 : convert hours seconds

$seconds = strtotime("1970-01-01 $maritime utc"); 

step 2 : multiply directly

$multiply = $seconds * 5; 

step 3 : convert seconds hours, , you're done !

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

so final code shall be

<?php $maritime ='01:10:00'; $seconds = strtotime("1970-01-01 $maritime utc"); $multiply = $seconds * 5;  #here can multiply dynamic value echo gmdate("d h:i:s",$multiply); 

here link of eval shows output

update :

if work more 1 day

i.e., time * 25 times, have more 1 day

then output 02 05:10:00

but if want in hours strictly should use datetime

<?php $maritime ='01:10:00'; $seconds = strtotime("1970-01-01 $maritime utc"); $multiply = $seconds * 25;  #here can multiply 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 eval link


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -