将日期转换为数小时 [英] Convert dates to hours
问题描述
我正在尝试第一次使用日期,我用Flash做了一些事情,但是却有所不同。
我有两个不同的日期, '我想看看他们的时间和日子的差异,我发现了太多的例子,但是我没有找到什么:
<?php
$ now_date = strtotime(date('Ymd H:i:s')); //当前日期
$ key_date = strtotime(date(2009-11-21 14:08:42));
打印日期($ now_date - $ key_date);
//它返回一个像5813,5814,5815等等的整数(我假定它们是秒)
?>
如何将其转换为数小时或数天?
替代方法将是数学。
如何将它[秒]转换为数小时或数天?
< blockquote>
每分钟有60秒,这意味着每小时3600秒。
$ hours = $ seconds / 3600;
当然,如果你需要几天...
$ days = $ hours / 24;
I'm trying to work with dates for the first time, I did it something about that with Flash but it's different.
I have two different dates and I'd like to see the difference in hours and days with them, I've found too many examples but not what I'm loking for:
<?php $now_date = strtotime (date ('Y-m-d H:i:s')); // the current date $key_date = strtotime (date ("2009-11-21 14:08:42")); print date ($now_date - $key_date); // it returns an integer like 5813, 5814, 5815, etc... (I presume they are seconds) ?>
How can I convert it to hours or to days?
解决方案Well, you can always use date_diff, but that is only for PHP 5.3.0+
The alternative would be math.
How can I convert it [seconds] to hours or to days?
There are 60 seconds per minute, which means there are 3600 seconds per hour.
$hours = $seconds/3600;
And, of course, if you need days ...
$days = $hours/24;
这篇关于将日期转换为数小时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!