drm30963 2015-11-26 05:05
浏览 268

如何将日期转换为小时

I am having :

hours1 : 403440

and date2 as :2016/01/10

I need to convert date2 in hours and find the difference between the two which should again be in hours.

  • 写回答

2条回答 默认 最新

  • doutan1970 2015-11-26 05:17
    关注

    The second parameter of date is a unix timestamp which is in seconds so multiple your hours by 3600 (3600 seconds per hour).

    $hours1 = 403440 * 3600;
    $date1 = date("d-m-Y H:i:s", $hours1);
    echo $date1;
    

    Output:

    09-01-2016 19:00:00
    

    Per your update your code should be:

    $date2 = strtotime('2016/01/10');//get date to seconds from 1970
    $hours1 = 403440 * 3600; // convert from hours to seconds
    echo ($date2 - $hours1)/3600;//subtract seconds then divide by 3600 to get how many hours difference is
    

    Output:

    5
    
    评论

报告相同问题?

悬赏问题

  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line