如何在PHP中以人类可读格式显示时差? [英] How to display time difference in a human readable format in php?

查看:127
本文介绍了如何在PHP中以人类可读格式显示时差?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

PHP:是否有一个以人类可读格式转换日期字符串的功能


我有一个具有以下结构的mysql表:



表:persons
column1:name varchar(60)
column2:score int(11)
column3:time datetime(60)



我有一个表单,将数据插入到这个表中:name,score和当前时间戳(NOW()),使用php。所有数据按照时间列按降序显示。



我的困境是如何将时间列中的时间与当前时间进行比较并使用php以5分钟前或2小时前的人类可读格式显示。有什么功能可以直接在PHP中找到时差吗?还是应该使用javascript?

解决方案

Althiough这个网站更多的是爱好者而不是程序员,我会这样回答: p>

为什么不尝试自己写这样的功能?

这不会太难,这可能是一个很好的做法。

你说什么?


Possible Duplicate:
PHP: Is there a function that converts a date string in a human readable format?

I have a mysql table with a structure as follows:

table: persons column1: name varchar(60) column2: score int(11) column3: time datetime(60)

I have a form which inserts data into this table: name, score and the current timestamp(NOW()), using php. All the data is displayed with respect to the 'time' column in descending order.

My dilemma is how do I compare the time in the 'time column' with current time and display in human readable format like "5 minutes ago" or "2 hours ago" using php. Is there any function to find time difference in php directly? or should i be using javascript?

解决方案

Althiough this site is more for the "enthusiasts" rather than "programmers", I'd answer this way:

Why not to try to write such a function yourself?
It is not going to be too hard and it could be a good practice.
What do you say?

这篇关于如何在PHP中以人类可读格式显示时差?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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