计算2 个时间差几个月

来源:互联网 发布:裙子太短 知乎 编辑:程序博客网 时间:2024/04/28 00:47
<?php // 时间戳,秒数//$time1 = 1445848035;//$time2 = 1487752035; $time1 = strtotime("2015-05-01 00:00:0");$time2 = strtotime("2016-10-29 00:00:0"); $year1  = date("Y",$time1);   // 时间1的年份$month1 = date("m",$time1);   // 时间1的月份  $year2  = date("Y",$time2);   // 时间2的年份$month2 = date("m",$time2);   // 时间2的月份  // 开始的年月echo $year1."年,".$month1."月"; echo "<br>"; // 结束的年月echo $year2."年,".$month2."月"; echo "<br>"; // 相差的月份echo ($year2 * 12 + $month2) - ($year1 * 12 + $month1);?>

0 0
原创粉丝点击