使用 strtotime() 将日期转换为新格式不起作用

问题描述 投票:0回答:1

我的数据库中有这样的日期格式'13/09/2022'但是我的客户建议将此格式更改为这种格式'09/13/2022'所以我使用

strtotime()
但没有正确结果它给出了这种结果01/01/1970你可以看到它给了我错误的结果。有人能解释一下发生了什么吗?

这是我的代码:

<?php 
$oldDate = '13/09/2022';
$newDate = date("m/d/Y", strtotime($oldDate)); 
echo $newDate; 
?> 
php date date-format
1个回答
0
投票

你可以试试这个:

echo DateTimeImmutable::createFromFormat('d/m/Y', '13/09/2022')->format("m/d/Y");

根据文档,“DD/MM/YY”不是标准格式:https://www.php.net/manual/en/datetime.formats.php.

© www.soinside.com 2019 - 2024. All rights reserved.