博客
关于我
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/

你可能感兴趣的文章
Perl的基本語法
查看>>
perl输出中文有乱码
查看>>
Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password). 大数据ssh权限问题 hadoop起不来 hadoopssh错
查看>>
PermissionError:Python 中的 [Errno 13]
查看>>
PermissionError:[Errno 13] 权限被拒绝:‘/manage.py‘
查看>>
Permutation
查看>>
perspective意思_2020年12月英语四级词汇讲解丨考点归纳:perspective
查看>>
PE文件,节头有感IMAGE_SECTION_HEADER
查看>>
PE查找文件偏移地址
查看>>
PE知识复习之PE的导入表
查看>>
PFX(Parallel Framework) and Traditional Multithreading
查看>>
PGOS:今天动手给电脑装青苹果Win7 X64位系统
查看>>
pgpool-II3.1 的内存泄漏(一)
查看>>
PgSQL · 特性分析 · PG主备流复制机制
查看>>
PGSQL主键序列
查看>>
PGSQL安装PostGIS扩展模块
查看>>
Phalcon环境搭建与项目开发
查看>>
Phantom.js维护者退出,项目的未来成疑
查看>>
Pharmaceutical的同学们都看过来,关于补码运算的复习相关内容
查看>>
phoenix无法连接hbase shell创建表失败_报错_PleaseHoldException: Master is initializing---记录020_大数据工作笔记0180
查看>>