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

你可能感兴趣的文章
thinkphp 常用SQL执行语句总结
查看>>
Oracle:ORA-00911: 无效字符
查看>>
Text-to-Image with Diffusion models的巅峰之作:深入解读 DALL·E 2
查看>>
TCP基本入门-简单认识一下什么是TCP
查看>>
tableviewcell 中使用autolayout自适应高度
查看>>
Orcale表被锁
查看>>
svn访问报错500
查看>>
org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned
查看>>
org.apache.ibatis.type.TypeException: Could not resolve type alias 'xxxx'异常
查看>>
org.apache.poi.hssf.util.Region
查看>>
org.apache.xmlbeans.XmlOptions.setEntityExpansionLimit(I)Lorg/apache/xmlbeans/XmlOptions;
查看>>
org.apache.zookeeper.KeeperException$ConnectionLossException: KeeperErrorCode = ConnectionLoss for /
查看>>
org.hibernate.HibernateException: Unable to get the default Bean Validation factory
查看>>
org.hibernate.ObjectNotFoundException: No row with the given identifier exists:
查看>>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
查看>>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
查看>>
org.springframework.web.multipart.MaxUploadSizeExceededException: Maximum upload size exceeded
查看>>
org.tinygroup.serviceprocessor-服务处理器
查看>>
org/eclipse/jetty/server/Connector : Unsupported major.minor version 52.0
查看>>
org/hibernate/validator/internal/engine
查看>>