Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php strotime减去小时和分钟_Php_Time_Strtotime - Fatal编程技术网

Php strotime减去小时和分钟

Php strotime减去小时和分钟,php,time,strtotime,Php,Time,Strtotime,我有以下代码: <?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

我有以下代码:

<?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; 
?>

但是不起作用,你知道吗

提前感谢

此函数只需要两个参数

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

strotime
的可能副本只接受2个参数,而不是3个。把小时和分钟放在同一个字符串中。检查我的答案。因为代码越少越好;)
$time=time();
$datetime_from = date("Y-m-d H:i", strtotime("-43 minutes", strtotime("-6 hours",$time)));