这种时间格式是中国标准时间,可以通过以下代码将其转换为PHP标准格式(即UNIX时间戳):

$date = '25/11/2020 下午4:00:00';
$timestamp = strtotime(str_replace('/', '-', $date));
echo $timestamp; // 输出 1606252800,即2020年11月25日 08:00:00 UTC

解释一下代码:

  1. 首先将日期中的斜杠替换为短横线,这是因为strtotime函数只接受短横线作为分隔符。
  2. 然后使用strtotime函数将日期字符串转换为UNIX时间戳。
  3. 最后输出时间戳即可。

完整代码如下:

<?php
$date = '25/11/2020 下午4:00:00';
$timestamp = strtotime(str_replace('/', '-', $date));
echo $timestamp; // 输出 1606252800,即2020年11月25日 08:00:00 UTC
?>
将'25/11/2020 下午4:00:00' 这种时间格式转换为PHP标准时间戳

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

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