Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/258.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
无法使用date()在PHP中获取正确的当前时间_Php - Fatal编程技术网

无法使用date()在PHP中获取正确的当前时间

无法使用date()在PHP中获取正确的当前时间,php,Php,假设我有一个页面abc.php,下面是php代码 <?php $current_time = date("Y-m-d H:i:s",time()); $curtim=strtotime($current_time); echo $current_time.' '.$curtim; ?> 此页面仅打印当前时间,如2015-07-27 14:18:18。当我以“无害的态度”工作时,我得到了正确的时间 当我关闭选项卡并在一段时间后使用快捷键-Ctlr+Shift+T

假设我有一个页面
abc.php
,下面是php代码

<?php
   $current_time = date("Y-m-d H:i:s",time());
   $curtim=strtotime($current_time);
   echo $current_time.' '.$curtim;
?>

此页面仅打印当前时间,如2015-07-27 14:18:18。当我以“无害的态度”工作时,我得到了正确的时间

当我关闭选项卡并在一段时间后使用快捷键-Ctlr+Shift+T重新打开它时,我仍然得到2015-07-27 14:18:18作为当前时间。 我猜这个页面不会用那个短键重新加载


当出现此类情况时,是否有方法正确获取当前时间???

如果问题是正在缓存的页面,则某些标题应予以修复

看这里


您正在使用该快捷方式“原样”打开此页面。您可以使用javascript显示时间,或者使用AJAX调用从PageLoad上的服务器获取时间。我认为,因为页面是缓存的,如果您刷新页面,时间应该更改吗?@Andrew我知道刷新页面可以获取正确的时间,但我们不能依赖用户。他们可以使用任何方法进入页面。这就是我提出这个问题的原因。我不认为这个问题是特定于PHP的…@aimme是的,我认为这是一个PHP问题,因为我看到了标签。。。如果datetime是一个问题,那么最好将其存储在数据库中,并设置为utc时间,并在请求时转换回用户..至少这是我使用的。。
header("Cache-Control: no-cache, no-store, must-revalidate"); // HTTP 1.1.
header("Pragma: no-cache"); // HTTP 1.0.
header("Expires: 0"); // Proxies.