date()返回不一致的时间 [英] date() returns inconsistent time

查看:103
本文介绍了date()返回不一致的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Mac Book Pro上的本地apache2网络服务器上使用PHP 5.3.8和默认时区设置为欧洲/苏黎世:

  $ now = time(); 
$ in5min = $ now + 300;

echonow:。 date('H:m:s',$ now);
echo< br>在5分钟内:。日期('H:m:s',$ in5min);

echo< br>现在只使用日期:。日期('H:m:s');

结果如下(2012年7月26日18:16:12运行):

 现在:18:07:01 
在5分钟内:18:07:01
现在只使用日期: 18:07:01

请注意,我可以刷新页面 - 秒更改,小时和分钟剩下所以5分钟后,它仍然是 18:07



我的网络服务器设置有什么问题?为什么时间计算不起作用?

解决方案

正确的格式字符串是 i 分钟,而不是 m m 几个月。

  date('H:i:s'); 


I have the following PHP code on my local apache2 webserver on a Mac Book Pro using PHP 5.3.8 and Default timezone set to Europe/Zurich:

$now = time();
$in5min = $now + 300;

echo "now: " . date('H:m:s', $now);
echo "<br>in 5 min: " . date('H:m:s', $in5min);

echo "<br>now using date only: " . date('H:m:s');

Result looks like this (run at 18:16:12, 26 July 2012):

now: 18:07:01  
in 5 min: 18:07:01  
now using date only: 18:07:01 

Note that I can refresh the page - the seconds change, the hours and minutes remain. So 5 minutes later it's still 18:07.

What's wrong with my webserver settings? And why does the time calculation not work?

解决方案

The correct format string is i for minutes, not m. m is for months.

date('H:i:s');

这篇关于date()返回不一致的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆