wordpress使用strtotime转为timestamp时间戳相差8小时

wordpress uses strtotime to convert timestamp to timestamp with a difference of 8 hours

假设原时间2022-09-16 15:19

使用strtotime转换后

strtotime('2022-09-16 15:19')

结果1663341544

在换成时间2022-09-16 23:19:04

时间相差8小时,

百度半天半天没找到,最后在google里找到解决办法,

单独封装一个strtotime函数

function wp_strtotime($str) {
         try {
            $datetime = new DateTime($str, wp_timezone());
         } catch (Exception $e)  {
            return false;
       }
       return $datetime->format('U');
    } 

如果在使用php自带date把时间戳转为时间的话也是相差8小时,

那么使用wordpress自带的wp_date()

参考:

https://gist.github.com/anthonyeden/0cf8eb86f7e634b3d5ded4debc59cb84

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注




Enter Captcha Here :