dongwusang0314 2019-04-16 15:56
浏览 47

如何在PHP中格式化H-i-m中的两个时间变量? [重复]

This question already has an answer here:

I want to calculate total working hours of an employee for a month.The time for one session of an employee is stored in the format 'H:i:s' as as string in the database.How do I add these individual sessions to calculate total time.

</div>
  • 写回答

1条回答 默认 最新

  • douhu1990 2019-04-16 16:06
    关注

    The function strtotime(datetime_today) will parse to seconds relative to the difference between the current datetime and 01/01/1970

    <?php
    
    $datetime_ref_today = '0:00:00';
    
    $ar_times[]='00:00:10';
    $ar_times[]='00:01:30';
    $ar_times[]='13:50:30';
    
    $total_time = 0;
    foreach($ar_times as $val)
    {
      $total_time += strtotime($val)-strtotime($datetime_ref_today);
      echo "<br/>cumul. total_time : ".$total_time." sec";;
    }
    
    echo "<br/><br/>total_time : ".$total_time." sec";
    echo "<br/>Formated total_time (H:i:s): ".gmdate("H:i:s", $total_time);
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么