在php中,从给定日期减少100年 $date_raw='1995年5月5日'; $newDate=(日期('jfy',标准时间('-192years-14个月-2天',标准时间('date_raw))); 打印“新日期:$newDate”;
我试着从一个给定的日期减去100多年。但我得到的价值只有92年才是真实的。在那之后,我没有得到正确的减法。原因是什么 如果需要处理32位有符号unix时间戳(1901-12-13到2038-01-19)范围之外的日期,请开始使用 给予在php中,从给定日期减少100年 $date_raw='1995年5月5日'; $newDate=(日期('jfy',标准时间('-192years-14个月-2天',标准时间('date_raw))); 打印“新日期:$newDate”;,php,Php,我试着从一个给定的日期减去100多年。但我得到的价值只有92年才是真实的。在那之后,我没有得到正确的减法。原因是什么 如果需要处理32位有符号unix时间戳(1901-12-13到2038-01-19)范围之外的日期,请开始使用 给予 或者,您可以通过以下方式执行此操作 3 March 1802 这将为您提供以下输出 // set your date here $mydate = "2018-06-27"; /* strtotime accepts two parameters. The
或者,您可以通过以下方式执行此操作
3 March 1802
这将为您提供以下输出
// 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);
原因很简单:
UNIX时间戳
如果您需要处理32位有符号UNIX时间戳范围之外的日期(1901-12-13到2038-01-19),那么开始使用$date_raw='05/05/1995'$newDate=(newdatetime($date_raw))->sub(newdateinterval('P192Y14M2D'))->格式('jfy');打印“新日期:$newDate
”代码>任何例子请??我是PHP新手,我尽了最大努力来解决这个问题。如果你能给我举个例子,我将不胜感激。我接受了这个答案。顺便说一下,我的问题不应该被否决。来这里之前,我在网上对我的问题做了深入的研究。但不管是谁干的,肯定对新来者有偏见。
3 March 1802
// 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