我有这个代码:
<?php
$date = date('Y-m-d H:i:s', strtotime('-6 hours', (int)get_the_time('U')));
echo $date;
?>
如您所见,通过从时间中减去 6 小时来更改时间,我想减去小时和分钟,所以我尝试了这个:
<?php
$date = date('Y-m-d H:i:s', strtotime('-6 hours', '-23 minutes', (int)get_the_time('U')));
echo $date;
?>
但是不起作用,知道吗?
提前谢谢你
strtotime 函数只需要 2 个参数。
int strtotime ( string $time [, int $now = time() ] )
因此,您应该尝试以下格式:
$date = strtotime('-6 hours, -43 minutes', $time);
测试代码:
<?php
$time = time();
$date = strtotime('-6 hours', $time);
echo date('d-m-y H:i', $time);
echo date('d-m-y H:i', $date);
$date = strtotime('-6 hours, -43 minutes', $time);
echo date('d-m-y H:i', $time);
echo date('d-m-y H:i', $date);
输出:
19-10-17 00:44
18-10-17 18:44
19-10-17 00:44
18-10-17 18:01
$time=time();
$datetime_from = date("Y-m-d H:i", strtotime("-43 minutes", strtotime("-6 hours",$time)));