如何计算PHP中两个时间点相差的年月日数?
- 内容介绍
- 文章标签
- 相关推荐
本文共计234个文字,预计阅读时间需要1分钟。
1. 将一年定义为360天,一个月定义为30天;
2.代码中86400表示一天有24小时*60分钟*60秒;
3.两个时间都需要按照类似2013-07-28的格式进行规范;
4.将代码推广到所有PHP程序,可以使用Get_option('swt_b')。
<?php //Get detail gap of year,month and days between two different time by vfhky 20130728 $common = (time()-strtotime(get_option('swt_builddate'))); $a = floor($common/86400/360); //整数年 $b = floor($common/86400/30) - $a*12; //整数月 $c = floor($common/86400) - $a*360 - $b*30; //整数日 $d = floor($common/86400); //总的天数 echo $a."年".$b."月".$c."日(共计".$d."天)"; ?>
本文共计234个文字,预计阅读时间需要1分钟。
1. 将一年定义为360天,一个月定义为30天;
2.代码中86400表示一天有24小时*60分钟*60秒;
3.两个时间都需要按照类似2013-07-28的格式进行规范;
4.将代码推广到所有PHP程序,可以使用Get_option('swt_b')。
<?php //Get detail gap of year,month and days between two different time by vfhky 20130728 $common = (time()-strtotime(get_option('swt_builddate'))); $a = floor($common/86400/360); //整数年 $b = floor($common/86400/30) - $a*12; //整数月 $c = floor($common/86400) - $a*360 - $b*30; //整数日 $d = floor($common/86400); //总的天数 echo $a."年".$b."月".$c."日(共计".$d."天)"; ?>

