Php 来自Unix时间戳的stringtotime

Php 来自Unix时间戳的stringtotime,php,date,strtotime,Php,Date,Strtotime,我在php脚本中执行以下操作,但没有看到我认为会出现的结果: $current_date_num = strtotime("now"); echo $current_date_num ." BEFORE DATE HOUR<br/>"; $new_current = date('Y-m-d h:i:s', strtotime($current_date_num)); echo $new_current . " AFTER DATE<br/>"; $curr

我在php脚本中执行以下操作,但没有看到我认为会出现的结果:

$current_date_num = strtotime("now");
   echo $current_date_num ." BEFORE DATE HOUR<br/>";

$new_current = date('Y-m-d h:i:s', strtotime($current_date_num));
   echo $new_current . " AFTER DATE<br/>";

$current_date_num = date('Y-m-d h:i:s', strtotime($current_date_num) - 60 * 60 * 6);
   echo $current_date_num ." CURRENT<br/>";

$end_date = strtotime("+1 day");
$end_date = date("Y-m-d h:i:s",$end_date);
   echo $end_date ." END DATE";

我想会发生的是,我得到Unix时间戳,然后使用strotime得到当前时间,然后得到当前时间减去6小时,最后是24小时后的时间。不知道我怎么会把事情搞得这么糟?

你应用的strotime()太多了两倍。第4行中有一次:

strtotime($current_date_num)

删除它,并在第7行中调用
strotime()

您应用的strotime()
太多了两倍。第4行中有一次:

strtotime($current_date_num)
删除它,并在第7行中调用
strotime()

获取人类可读的时间并将其解析为时间戳。由于您已经有了时间戳,strtime调用正在生成虚假数据

$current_date_num = strtotime("now");
echo $current_date_num ." BEFORE DATE HOUR<br/>";

$new_current = date('Y-m-d h:i:s', $current_date_num);
echo $new_current . " AFTER DATE<br/>";

$current_date_num = date('Y-m-d h:i:s', $current_date_num - 60 * 60 * 6);
echo $current_date_num ." CURRENT<br/>";

$end_date = strtotime("+1 day");
$end_date = date("Y-m-d h:i:s",$end_date);
echo $end_date ." END DATE";
获取人类可读的时间并将其解析为时间戳。由于您已经有了时间戳,strtime调用正在生成虚假数据

$current_date_num = strtotime("now");
echo $current_date_num ." BEFORE DATE HOUR<br/>";

$new_current = date('Y-m-d h:i:s', $current_date_num);
echo $new_current . " AFTER DATE<br/>";

$current_date_num = date('Y-m-d h:i:s', $current_date_num - 60 * 60 * 6);
echo $current_date_num ." CURRENT<br/>";

$end_date = strtotime("+1 day");
$end_date = date("Y-m-d h:i:s",$end_date);
echo $end_date ." END DATE";

现在我明白了。谢谢,让我更新一下,看看会发生什么+现在我明白了。谢谢,让我更新一下,看看会发生什么+1.