如何在PHP中以人类可读格式显示时差?

编程入门 行业动态 更新时间:2024-10-26 05:21:32
本文介绍了如何在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中以人类可读格式显示时差?

本文发布于:2023-11-11 06:32:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1577641.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:时差   中以   可读   人类   格式

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!