php – 返回最后2位数字

前端之家收集整理的这篇文章主要介绍了php – 返回最后2位数字前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何获取最后2位数字:
<departureDate>200912</departureDate>

对我的对象:@H_403_4@

$year = $flightDates->departureDate->year;
// first two
$year = substr($flightDates->departureDate->year,2);
// last two
$year = substr($flightDates->departureDate->year,-2);

但是考虑到你在这里解析一个日期,使用date函数会更加智慧.
体育strtotime()和date()或甚至:@H_403_4@

<?PHP
$someDate ='200912';
$dateObj = DateTime::createFromFormat('dmy',$someDate);
echo $dateObj->format('Y');
// prints "2012" .. (see date formats)
原文链接:https://www.f2er.com/php/131669.html

猜你在找的PHP相关文章