PHP 将 25/11/2020下午4:00:00 格式转换为标准时间格式
可以使用 PHP 的 date() 函数将该格式转换为标准时间格式。示例代码如下:
$date_str = '25/11/2020下午4:00:00';
$date = DateTime::createFromFormat('d/m/Y下午h:i:s', $date_str);
echo $date->format('Y-m-d H:i:s');
输出结果为:2020-11-25 16:00:00。
在上述代码中,使用 DateTime::createFromFormat() 函数将输入的日期字符串转换为 DateTime 对象,同时指定输入字符串的格式。然后使用 format() 方法将 DateTime 对象格式化为标准时间格式。
原文地址: https://www.cveoy.top/t/topic/lBo3 著作权归作者所有。请勿转载和采集!