我从XML文件中检索一个具有两位数字年份的日期,例如“ dd / mm / yy”。我如何将其更改为“ yyyymmdd”格式。感谢您的帮助
这是我尝试过的方法,但是我要将此日期定为1970年1月1日:
$date = str_replace('/', '-', $date_reception);
$timestamp = strptime($date);
$this->date_reception = date("Ymd", $timestamp);
您可以使用DateTime::createFromFormat()
功能
http://php.net/manual/fr/datetime.createfromformat.php
$input = '01/05/16';
$dateTime = \DateTime::createFromFormat('d/m/y', $input);
echo $dateTime->format('Ymd'); // will output 20160501
// or in one line
$date = \DateTime::createFromFormat('d/m/y', $input)->format('Ymd');
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句