$date_raw = '05/05/1995';
$newDate = (date('j F Y', strtotime('-192years -14months -2days', strtotime($date_raw))));
print "New Date: $newDate <br>";
我试图从给定日期减去100多年。但我得到的价值只有92年才真实。之后我没有得到正确的减法。什么原因?
答案 0 :(得分:1)
如果您需要处理超出32位有符号unix时间戳(1901-12-13到2038-01-19)范围的日期,请开始使用DateTime objects
$date_raw = '05/05/1995';
$newDate = (new DateTime($date_raw))
->sub(new DateInterval('P192Y14M2D'))
->format('j F Y');
echo $newDate, PHP_EOL;
给出
3 March 1802
答案 1 :(得分:0)
或者您可以通过以下方式进行
// set your date here
$mydate = "2018-06-27";
/* strtotime accepts two parameters.
The first parameter tells what it should compute.
The second parameter defines what source date it should use. */
$lastHundredyear = strtotime("-100 year", strtotime($mydate));
// format and display the computed date
echo date("Y-m-d", $lastHundredyear);
这将为您提供以下输出
1918-06-27