所以,我们有以下代码:
date("Y-m-d",time()+60*365*24*60*60);
想法是我必须做出预测,并且我得到的结果是我必须添加到当前日期的天数。预测是在2060年或过去...在64位环境中工作,但在32位上没有那么多:)
任何想法?
10倍。
LE
好的,我已经尝试过了:
$date = new DateTime();
// for PHP 5.3
$date->add(new DateInterval('P20000D'));
// for PHP 5.2
$date->modify('+20000day');
echo $date->format('Y-m-d') . "\n";
并且有效
答案 0 :(得分:2)
这适用于我的32位系统:
$date = new DateTime("2071-05-26");
echo $date->format('Y-m-d H:i:s');
//我在this问题
中看到了这一点答案 1 :(得分:1)
见:
http://www.infernodevelopment.com/forum/Thread-Solution-2038-PHP-Date-Bug-Y2-038K-UNIX-TIMESTAMP-BUG
<?php
// Specified date/time in your computer's time zone.
$date = new DateTime('9999-04-05');
echo $date->format('Y-M-j') ."";
// Specified date/time in the specified time zone.
$date = new DateTime('2040-09-08', new DateTimeZone('America/New_York'));
echo $date->format('n / j / Y') . "";
// INPUT UNIX TIMESTAMP as float or bigint from database
// Notice the result is in the UTC time zone.
$r = mysql_query("SELECT date FROM test_table");
$obj = mysql_fetch_object($r);
$date = new DateTime('@'.$obj->date); // a bigint(8) or FLOAT
echo $date->format('Y-m-d H:i: sP') ."";
// OR a constant greater than 2038:
$date = new DateTime('@2894354000'); // 2061-09-19
echo $date->format('Y-m-d H:i: sP') ."";
?>
答案 2 :(得分:0)
如果您要添加完整年/日/月,我想您可以单独使用简单算术,然后使用checkdate()
(it claims to work up to year 32767)来验证结果
$date = array('Y' => date('Y'), 'm' => date('n'), 'd' => date('j'));
// +60 years
$date['Y'] += 60;
if (checkdate($date['m'], $date['d'], $date['Y'])) {
$fulldate = implode('-', $date);
}
答案 3 :(得分:0)
<?php
// A dirty hack
function bigdate_to_string($t_64bit)
{
$t_base = strtotime('2038-01-01 00:00:00 +0000');
$t_32bit = $t_64bit - $t_base;
return date("Y", $t_32bit) + 68 . date("-m-d H:i:s", $t_32bit);
}
$t_64bit = 130 * 365 * 86400; // November 30, 2099 UTC
echo bigdate_to_string($t_64bit) . "\n";
?>
输出:
susam@swift:~$ php datehack.php
2099-11-30 05:30:00
我正在减去68年,并在打印格式化输出时再次添加它。