从 wordpress 中减去 6 小时 get_the_time

subtract 6 hours from wordpress get_the_time

我正在尝试从 wordpress 函数中减去一定的小时数 get_the_time();所以 post 看起来像是之前 post 编辑过的。

这是我的代码:

<?php  function displaytime() {
return get_the_time(strtotime( '-6 hours' ) );
}
        echo displaytime(); ?>

问题是现在的输出是:1506910342

有人能帮帮我吗?

提前致谢

1506910342 是 unix 时间戳。

您可以简单地使用 this 方法从 unix 时间戳中获取日期时间

例如:

$ts = get_the_time(); 
$ts -= 6 * 60 * 60;
$date = new DateTime();
$date->setTimestamp($ts);

如您在 docs, first param for get_the_time function is date format and it returns string in your specified format. So instead you can use U as a first parameter, so you will get UNIX time, then subtract 6 hours using strtotime, and format it again with date 函数中所见:

 date('Y-m-d H:i:s', strtotime('-6 hours', (int)get_the_time('U')));