当前位置:网站首页>php convert timestamp to just, minutes ago, hours ago, days ago format
php convert timestamp to just, minutes ago, hours ago, days ago format
2022-08-08 23:11:00 【Do you still believe in light?】
The following are several ways of php implementation, you can choose by yourself
//Convert the timestamp to minutes or hours or days agofunction wordTime($time) {$time = (int) substr($time, 0, 10);$int = time() - $time;$str = '';if ($int <= 30){$str = sprintf('Just now', $int);}elseif($int < 60){$str = sprintf('%d seconds ago', $int);}elseif ($int < 3600){$str = sprintf('%d minutes ago', floor($int / 60));}elseif ($int < 86400){$str = sprintf('%d hours ago', floor($int / 3600));}elseif ($int < 2592000){$str = sprintf('%d days ago', floor($int / 86400));}else{$str = date('Y-m-d H:i:s', $time);}return $str;}
function mdate($time = NULL) {$text = '';$time = $time === NULL || $time > time() ? time() : intval($time);$t = time() - $time; // time difference (seconds)$y = date('Y', $time)-date('Y', time());//Whether New Year's Eveswitch($t){case $t == 0:$text = 'Just now';break;case $t < 60:$text = $t . 'seconds ago'; // within a minutebreak;case $t < 60 * 60:$text = floor($t / 60) . 'minutes ago'; //within an hourbreak;case $t < 60 * 60 * 24:$text = floor($t / (60 * 60)) . 'hour ago'; // within a daybreak;case $t < 60 * 60 * 24 * 3:$text = floor($time/(60*60*24)) ==1 ?'Yesterday' .date('H:i', $time) : 'The day before yesterday' .date('H:i', $time) ; //yesterday and the day before yesterdaybreak;case $t < 60 * 60 * 24 * 30:$text = date('m month d day H:i', $time); //within a monthbreak;case $t < 60 * 60 * 24 * 365&&$y==0:$text = date('m month d day', $time); //within one yearbreak;default:$text = date('Y year m month d day', $time); //a year agobreak;}return $text;}
I hope this helps!!!!
边栏推荐
- [Bug solution] ValueError: Object arrays cannot be loaded when allow_pickle=False
- C language library function summary2019.10.31
- ndk和JNI的使用初探
- JSDay1-两数之和
- (Codeforce 757)E. Bash Plays with Functions(积性函数)
- (2022牛客多校五)H-Cutting Papers(签到)
- 想要精准营销,从学习搭建一套对的标签体系开始丨DTVision分析洞察篇
- (newcoder 15079)无关(容斥原理)
- 【PP-YOLOv2】训练自定义的数据集
- 微信小程序错误 undefined Expecting ‘STRING‘,‘NUMBER‘,‘NULL‘,‘TRUE‘,‘FALSE‘,‘{‘,‘[‘, got ]解决方案
猜你喜欢
CTFSHOW_WEB入门web213
(newcoder 15079)无关(容斥原理)
Modal dialog is used to implement the sign-in
用工具实现 Mock API 的整个流程
微信小程序错误 undefined Expecting ‘STRING‘,‘NUMBER‘,‘NULL‘,‘TRUE‘,‘FALSE‘,‘{‘,‘[‘, got ]解决方案
(2022牛客多校二)L-Link with Level Editor I(动态规划)
PMP考点有哪些啊?
Manacher(求解最长回文子串)
wps表格下拉选项怎么添加?wps表格下拉选项的添加方法
【Pytorch】学习笔记(一)
随机推荐
wps备份与恢复在哪里?
STM8L 液晶数码管驱动,温度计液晶屏显示
(2022牛客多校四)A-Task Computing (排序+动态规划)
(nowcoder22529C)dinner(容斥原理+排列组合)
2021 RoboCom 世界机器人开发者大赛-本科组(决赛)7-4猛犸不上 Ban(最短路)
深拷贝与浅拷贝
2022牛客多校六 J-Number Game(简单推理)
加载 已训练模型 张量的 几种方法
Virtualization type (with picture)
(2022牛客多校四)K-NIO‘s Sword(思维)
CTF Attack and Defense World
【Verilog基础】PPA优化问题总结(含面积优化、速度优化)
【CUDA】版本自由切换
stm32 uses spi1 to read data from dma in slave mode
微信小程序 wx:for 循环输出 例子
【Pytorch】学习笔记(一)
【Bug解决】ValueError: Object arrays cannot be loaded when allow_pickle=False
Oracle 锁表,如何解锁
wps表格分两页断开怎么办?wps表格分两页断开的解决方法
(2022牛客多校五)D-Birds in the tree(树形DP)