基本上我需要显示距离指定时间还有多少时间,或者如果它过去了,它过去了多少时间。
原始字符串看起来就像这样:07/20/2011 01:13 am
编辑:从使用 javascript 转换为 php:
//get local time in UTC format
echo gmdate("Y/m/d\TH:i:s\Z");
echo '<br />';
//convert time to UTC
$the_date = strtotime("07/20/2011 01:13 am");
echo date("Y/m/d\TH:i:s\Z",$the_date);
执行上述操作后,我可以使用这些:
//local time
2011/07/20T19:49:39Z
//specified time
2011/07/20T01:13:00Z
如何获取指定时间和本地时间并使其显示如下示例:
Started 36 mins ago
Will start in 33 mins
Will start in 6 hrs 21 mins
Will start in 4 days 4 hrs 33 mins
最佳答案
如果你想用 Javascript 来做,它会稍微痛苦一些,但你会得到“实时”倒计时的好处。
这里详细介绍了如何做到这一点。
http://ditio.net/2010/05/02/javascript-date-difference-calculation/
关于php - 如何显示指定日期之前的时间或自指定日期以来的时间javascript或php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6759083/