博客
关于我
PHP 计算时间差
阅读量:121 次
发布时间:2019-02-26

本文共 1287 字,大约阅读时间需要 4 分钟。

<?php

/**
时间差计算
*
@param Timestamp $time
*
@return String Time Elapsed
*
@author Shelley Shyan
*
@copyright http://phparch.cn (Professional PHP Architecture)
*/
functiontime2Units($time){
$year = floor($time / 60 / 60 / 24 / 365); $time -= $year * 60 * 60 * 24 * 365; $month = floor($time / 60 / 60 / 24 / 30); $time -= $month * 60 * 60 * 24 * 30; $week = floor($time / 60 / 60 / 24 / 7); $time -= $week * 60 * 60 * 24 * 7; $day = floor($time / 60 / 60 / 24); $time -= $day * 60 * 60 * 24; $hour = floor($time / 60 / 60); $time -= $hour * 60 * 60; $minute = floor($time / 60); $time -= $minute * 60; $second = $time; $elapse = ''; // 定义时间单位数组 $unitArr = array( '年' => 'year', '个月' => 'month', '周' => 'week', '天' => 'day', '小时' => 'hour', '分钟' => 'minute', '秒' => 'second' ); // 循环计算各时间单位并累加 foreach ($unitArr as $cn => $u) { if ($u > 0) { $elapse .= "$u $cn "; break; } } return $elapse;}

$past = 2052345678;// 某个过去的时间戳$now = time();// 当前时间戳$diff = $now - $past;$diff = abs($diff);

发表于 time2Units($diff) 前

转载地址:http://sssf.baihongyu.com/

你可能感兴趣的文章
position:fixed失效情况
查看>>
Position属性四个值:static、fixed、absolute和relative的区别和用法
查看>>
POSIX thread编程中关于临界区内条件变量的分析
查看>>
POSIX与程序可移植性
查看>>
posix多线程有感--自旋锁
查看>>
SpringBoot中集成海康威视SDK实现布防报警数据上传/交通违章图片上传并在linux上部署(附示例代码资源)
查看>>
POSIX标准和XSI扩展
查看>>
post install error,please remove node_moules before retry
查看>>
PostGIS中获取所有EPSG的编码以及对应Proj4字符串
查看>>
PostGIS在Windows上的下载与安装
查看>>
postgis数据库优化_postgresql 性能优化
查看>>
Postgres Docker版本安装mysql_fdw 插件
查看>>
Postgres invalid command \N数据恢复处理
查看>>
Postgres like 模糊查询匹配集合
查看>>
Postgres 自定义函数内实现 in 操作符的递归查询
查看>>
Postgres 返回当前时间前后指定天数的集合
查看>>
postgres--vacuum
查看>>
postgres--wal
查看>>
postgres--流复制
查看>>
postgres10配置huge_pages
查看>>