我正在编写一些代码--一个脚本,它的日期很短,比如
14/12/17
30/11/17
20/11/17我需要将这些转换成长日期格式,因此我使用了PHP 日期函数和strtotime,如下所示
echo date('d-m-Y',strtotime('14/12/17'));但是它总是以01-01-1970作为输出,但它应该是14-12-2017。
任何人都知道如何将此格式转换为长日期格式。
PS.其他问题的答案建议更改日期输入格式,但我不能更改日期输入,因为它来自另一个站点
发布于 2017-12-30 07:46:22
这是我发布的链接,OP说是不对的。
最初由塞罗亚张贴。
Convert one date format into another in PHP
$myDateTime = DateTime::createFromFormat('d/m/y','14/12/17');
$newDateString = $myDateTime->format('d-m-Y');
Echo $newDateString;发布于 2017-12-30 07:56:50
使用preg_replace在传入日期上翻转日期和月份,然后根据需要使用日期。
$orig = ['14/12/17', '30/11/17', '20/11/17'];
foreach ($orig as $s) {
echo date('d-m-Y', strtotime(preg_replace('#(\d+)\/(\d+)\/(\d+)#', '$2/$1/$3', $s)))."\n";
}https://stackoverflow.com/questions/48031746
复制相似问题