0
A
回答
3
PHP的时间戳与Unix时间戳相同 - 自1970年1月1日以来的秒数。所以是的,一个简单的减法会给你一个秒钟的时间差,你可以通过潜水86,400(一天中的秒数) :
$days = (time() - $oldtimestamp)/86400;
0
尝试这种情况:
// Will return the number of days between the two dates passed in
function count_days($a, $b)
{
// First we need to break these dates into their constituent parts:
$gd_a = getdate($a);
$gd_b = getdate($b);
// Now recreate these timestamps, based upon noon on each day
// The specific time doesn't matter but it must be the same each day
$a_new = mktime(12, 0, 0, $gd_a['mon'], $gd_a['mday'], $gd_a['year']);
$b_new = mktime(12, 0, 0, $gd_b['mon'], $gd_b['mday'], $gd_b['year']);
// Subtract these two numbers and divide by the number of seconds in a
// day. Round the result since crossing over a daylight savings time
// barrier will cause this time to be off by an hour or two.
return round(abs($a_new - $b_new)/86400);
}
+0
只需获得时间戳差异,再加上可能与计算相关的“破坏”时间数据。 –
2
还有使用的,优选的,选择210和DateInterval
类。
$now = new DateTime;
$then = new DateTime;
$then->setTimestamp($timestamp);
$diff = $now->diff($then);
echo $diff->days;
以上也将提供的年数,月,日等应那些是你的兴趣(以及天总数如图所示)。
相关问题
- 1. 获取当前ISO8601日期/时间戳
- 2. Vb.net当前日期减去日期
- 3. 日期。减去从列当前日期
- 4. Android - 如何减去任何其他日期的当前日期
- 5. 如何从另一个日期时间减去日期时间?
- 6. 减去2日期时间并获得日期时间返回
- 7. 从python的csv文件的当前日期时间减去日期时间
- 8. 如何减去日期时间值并获取时间
- 9. 如何在PL/SQL中减去当前日期的日期
- 10. 如何从数据库中减去当前日期与日期
- 11. 减去日期时间
- 12. 减去日期时间列
- 13. 减去日期和时间
- 14. 2。减去日期时间
- 15. 日期时间减去uwp
- 16. 从当前时间戳获取日期时间默认
- 17. iOS Swift - 获取当前本地时间和日期时间戳
- 18. 如何从mysql中的当前日期时间减去30天?
- 19. 你如何从日期时间减去?
- 20. 用mysql从时间戳中减去日期时间
- 21. 如何获取和减去当前日期时间与我的表上的日期
- 22. 如何减去两个日期和时间来获得差异
- 23. 如何使用perl获取去年的日期和当前日期?
- 24. 如何自动获取当前日期和时间到日期时间字段
- 25. 如何减去日期日期在JavaScript
- 26. 无时间获取当前日期
- 27. 获取当前系统日期时间
- 28. XSLT 1.0获取当前日期时间
- 29. 获取当前日期和时间
- 30. 获取当前时间/日期purescript
我会添加'$ days = ceil($ days);'或'$ days = floor($ days);'。取决于要求 –
ceil很好地工作!谢谢 – 3cross