如何在php中的x天前显示时间 [英] How to display time in x days ago in php

查看:79
本文介绍了如何在php中的x天前显示时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的php页面上显示用户个人资料中的上次看到的内容。我将用户的注销时间存储在2014年1月6日15:25:08(存储在 $ last_log 中)中,数据类型为DATETIME。现在我想显示x分钟前的最后一次看到。而且它会在x天前,x月前自动更新。

I want to show last seen in user's profile in my php page. I am storing user's logout time in database as 2014-01-06 15:25:08 (store in $last_log) with DATETIME datatype. Now i want to display last seen x mins ago. And it's auto update in x day ago, x month ago.

我想在此处添加评论&它的时间 ....... ago更新。
如何显示此内容。

I want same as here when we add comment & its time ".......ago" updates. How can i display this.

推荐答案

尝试一下

$date1 = strtotime('2014-12-06 15:25:08');
$date2 = strtotime(date('Y-m-d H:i:s'));
$seconds_diff = $date2 - $date1;

echo round(abs($seconds_diff) / 60,2). " mins ago";

这篇关于如何在php中的x天前显示时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆