PHP实现时间比较和时间差计算的方法示例
本文实例讲述了PHP实现时间比较和时间差计算的方法。分享给大家供大家参考,具体如下:
示例1:
"; echo"zero2的时间为:".$zero2."
"; //strtotime—将任何英文文本的日期时间描述解析为Unix时间戳 if(strtotime($zero1)strtotime($zero2)){ echo"zero2早于zero1"; }else{ echo"zero2等于zero1"; } echo"
"; ?>
运行结果:
zero1的时间为:2017-07-2412:18:39 zero2的时间为:2010-11-2921:07:00 zero2早于zero1
示例2:
$guonian天!"; echo"
"; ?>
运行结果:
离过年还有161天
示例3:
"; ?>
运行结果:
现在距结束时间还有6天5小时339分钟56秒
PS:这里再为大家推荐几款时间及日期相关工具供大家参考使用:
在线日期/天数计算器:
http://tools.jb51.net/jisuanqi/date_jisuanqi
在线日期计算器/相差天数计算器:
http://tools.jb51.net/jisuanqi/datecalc
在线日期天数差计算器:
http://tools.jb51.net/jisuanqi/onlinedatejsq
Unix时间戳(timestamp)转换工具:
http://tools.jb51.net/code/unixtime
更多关于PHP相关内容感兴趣的读者可查看本站专题:《php日期与时间用法总结》、《PHP数组(Array)操作技巧大全》、《php面向对象程序设计入门教程》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》
希望本文所述对大家PHP程序设计有所帮助。