PHP计算两次之间的天数、小时数、分钟数和秒数:12:12";//结束时间$date=floor((strtotime($enddate)-strtotime($startdate))/86400);echo"天数差异:“.$date。”days
";$hour=floor((strtotime($enddate)-strtotime($startdate))%86400/3600);echo"时差:".$hour."hour
";$minute=floor((strtotime($enddate)-strtotime($startdate))%86400/60);echo"分钟差值:".$minute."分钟
";$second=floor((strtotime($enddate)-strtotime($startdate))%86400%60);echo"秒差:".$second."“秒”;不管是使用字符串构造的时间类型(使用strtotime转换来的都无所谓),还是直接使用系统的时间函数获取的时间类型,最后其实都是一个longinteger的变量。有了两个这样的变量,显然可以做减法。减法得到的值是秒差,这个秒数的余数是86400(一天的秒数),得到差值。如果对86400取模,取3600秒和60秒的余数,就可以得到相关的小时和分钟。如果先对86400取模,然后对60取模,就会得到以秒为单位的差值。
