过去日期和今天之间的输出时间 php
Output time time between a past date and today php
目前我有一个查询,它检查来自外部网站的日期并在该日期超过四个星期时给我一些信息:
$json = json_decode($result, true);
echo date("d.m.Y",strtotime($json[lastUpdated][when]));
$mydate = strtotime($json[lastUpdated][when]);
if ($mydate <= strtotime('4 weeks ago')) {
echo "Is not up to date!";
}
我想输出日期 $mydate
和今天之间经过了多少时间。谢谢!
您可以使用以下方法简单地计算两个日期之间的差异:
$mydate = strtotime($json['lastUpdated']['when']); // I guess the quotes are missing in your code
$now = time();
echo "The difference is " . ($now - $mydate) . " seconds";
如果您需要与秒数不同的东西,则必须计算这些值,例如
echo "The difference is " . (($now - $mydate)/60) . " minutes";
echo "The difference is " . (($now - $mydate)/60*60) . " hours";
echo "The difference is " . (($now - $mydate)/60*60*24) . " days";
目前我有一个查询,它检查来自外部网站的日期并在该日期超过四个星期时给我一些信息:
$json = json_decode($result, true);
echo date("d.m.Y",strtotime($json[lastUpdated][when]));
$mydate = strtotime($json[lastUpdated][when]);
if ($mydate <= strtotime('4 weeks ago')) {
echo "Is not up to date!";
}
我想输出日期 $mydate
和今天之间经过了多少时间。谢谢!
您可以使用以下方法简单地计算两个日期之间的差异:
$mydate = strtotime($json['lastUpdated']['when']); // I guess the quotes are missing in your code
$now = time();
echo "The difference is " . ($now - $mydate) . " seconds";
如果您需要与秒数不同的东西,则必须计算这些值,例如
echo "The difference is " . (($now - $mydate)/60) . " minutes";
echo "The difference is " . (($now - $mydate)/60*60) . " hours";
echo "The difference is " . (($now - $mydate)/60*60*24) . " days";