可以使用 strtotime() 函数将字符串转换为时间戳,然后再使用 date() 函数将时间戳转换为标准时间格式。以下是代码示例:

$time_str = '25/11/2020下午4:00:00';
$time_stamp = strtotime(str_replace(['上午', '下午'], '', $time_str));
$standard_time = date('Y-m-d H:i:s', $time_stamp);

echo $standard_time;

输出结果为:2020-11-25 16:00:00。

注意,由于原字符串中包含'下午'标识,需要使用 str_replace() 函数将其替换为空字符串,否则转换后的时间会有偏差。此外,输出的时间可能与本地时区不一致,可以使用 date_default_timezone_set() 函数设置时区。

PHP 转换时间字符串 '25/11/2020下午4:00:00' 到标准时间格式

原文地址: https://www.cveoy.top/t/topic/lBmT 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录