如何显示时间,直到或时间,因为指定日期javascript或php


how to display time until or time since a specified date javascript or php

基本上,我需要显示距离指定时间还有多少时间,或者如果已经过去了,那么距离它过去了多少时间。

原始字符串看起来就像这样: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/

参见手册。使用datediff的示例#3也会对您有所帮助。