日期操作不能正确工作


Date Manipulation Not Working Correctly

我试图将以这种格式"d/m/Y"显示的日期更改为这种格式"d-m-Y",我写了下面的代码:

//Add $license years to today
$today = date("j-m-Y");
$license = $row_customize['license'];
$startdate = $row_customize['startdate'];
list($d,$m,$Y) = explode('/',$startdate);
$newstartDate = $d."-".$m."-".$Y;
$enddate= date("j-m-Y", strtotime("$newstartDate +$license years"));
echo $today;
echo $enddate;

$today显示正确,但$enddate显示的是1970年的日期,例如1-01-1970。

请问我做错了什么?

我会把

$newstartDate = $d."-".$m."-".(intval($Y)+intval($license));
$enddate= date("j-m-Y", strtotime($newstartDate));

我认为格式"<date> + n years"不允许strtotime()

默认日期为0,即01-01-1970。所以$newstartDate和$license years都是0,所以当它们加在一起时,结果仍然是0。那么问题是为什么$newstartDate和$license设置为0。

我想就像p91paul说的,你可能无法使用n Years。我认为$newstartDate也可能是不支持的格式。是否可以在函数中使用$startDate,然后执行格式更改?