繁体   English   中英

PHP strtotime日期差

[英]PHP strtotime date difference

我想得到用户的年龄。 我试过了:

$dStart = strtotime('1985-10-24');
    $dEnd   = strtotime('2014-07-30');
    $dDiff  = $dEnd - $dStart;
    echo date('Y',$dDiff);

但是用1998代替28,正确的代码是什么?

strtotime()不是用于日期数学的。 DateTime()更好的适合这样的:

$dStart = new DateTime('1985-10-24');
$dEnd = new DateTime('2014-07-30');
$dDiff = $dStart->diff($dEnd);
echo $dDiff->y;

演示版

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM