打印一小时前的时间
可能的重复:
给定时间,我怎样才能找到一个月前的时间
如何使用 Date 在 PHP 中打印一小时前的时间?
$date=date("Y-m-d H:i:s");
$time(-1, now);
$result=$date.$time;
所以如果我想说“约翰最后访问过”
会打印
约翰于 2012 年 2 月 20 日 17.26 访问过
Possible Duplicate:
Given a time, how can I find the time one month ago
How can I print an hour ago in PHP using Date?
$date=date("Y-m-d H:i:s");
$time(-1, now);
$result=$date.$time;
So If I wanted to say "John visited last "
Would print
John visited last 20th Feb 2012, 17.26
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
时间() ->当前时间戳
时间减去 3600 秒,即 1 小时前的时间。要设置日期格式,您可以在此处查找选项:http://php. net/manual/en/function.date.php
或者,您可以使用以下格式:
尽管如果您想删除更具体的时间单位(例如一天和 3 小时),则使用该方法可能会有点笨拙)。
如果我明白你想要做什么的话那就是这样。
time() -> Current timestamp
Time minus 3600 seconds, is the time 1 hour ago. To get the date formatted, you can look here for the options: http://php.net/manual/en/function.date.php
Alternatively you could use the following format:
Though using that method can be a little clunky if you want to remove more specific units of time (Such as one day and 3 hours).
Thats if I've understood what you want to do correctly that is.
我想你会从 mysql 获取日期和时间,最好的办法是使用 mysql 的 DATE_FORMAT 函数并计算出来。
否则,在简单的 php 中你可以这样做
$date=date("Ymd H:i:s", $time -3600);
更好的选择是像这样使用 strtotime
$date=date("Ymd H:i:s", strtotime('-1 小时'));
并完成工作。
I suppose you would be fetching date and time from mysql and the best thing to do is using mysql's DATE_FORMAT function and work out.
Other wise in simple php you could do it like this
$date=date("Y-m-d H:i:s", $time -3600);
Better option is to use strtotime like this one
$date=date("Y-m-d H:i:s", strtotime('-1 hour'));
And get the work done.
嗯,搜索一下我使用的功能的手册。您缺少一些有关 PHP 日期/时间函数的信息...
Mmm, search the manual the function I used. You are missing something about PHP date/time functions...