首页 文章

如何找出2个时间戳之间的日期和分钟

提问于
浏览
0

我试图找出两个时间戳之间的年,月,日和分钟 .

我使用了以下代码,但它不起作用:

$diff = time()-$res['asked_on'];
$years = floor($diff / (365*60*60*24));
$months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
$days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));

我得到的输出为:

0
0
0

$ res ['ask_on'] = 1331980897(这也是从time()函数获取的时间戳)

1 回答

  • 0

    如果 $res['asked_on'] 是日期格式的字符串,则应使用strtotime将其转换为时间戳 .

    如果您的php> = 5.3,您可以查看php提供给您的方法:DateTime::diff

相关问题