作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我有:
hours1 : 403440
和 date2 为:
2016/01/10
我需要以小时为单位转换 date2 并找到两者之间的差异,它应该再次以小时为单位。
最佳答案
date
的第二个参数是以秒为单位的 unix 时间戳,因此您的小时数乘以 3600(每小时 3600 秒)。
$hours1 = 403440 * 3600;
$date1 = date("d-m-Y H:i:s", $hours1);
echo $date1;
输出:
09-01-2016 19:00:00
根据您的更新,您的代码应该是:
$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
输出:
5
关于php - 如何将日期转换为小时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33930956/
我是一名优秀的程序员,十分优秀!