PHP计算时差
计算时差不是件容易的事,因为日期-时间是多种进制混合在一起,需要转换成秒才能计算,比较麻烦,好在PHP提供了一个函数,能把一个时间(1970-2038之间的年)转换为相对 1970.01.01 0:0:0 的相对秒数值,这样就可以直接计算了。 函数格式:mktime(int hour, int minute, int second, int month, int day, int year); Code(时间用yymmddhhiiss格式,无空格,如:20090123095946) ?Download php-calc-shicha.txt1 2 3 4 5 6 7 function calc_shicha($t2,$t1) { $y=substr($t1,0,4);$m=substr($t1,4,2);$d=substr($t1,6,2);$h=substr($t1,8,2);$i=substr($t1,10,2);$s=substr($t1,12,2);//分离t1 $tt1=mktime($h,$i,$s,$m,$d,$y); $y=substr($t2,0,4);$m=substr($t2,4,2);$d=substr($t2,6,2);$h=substr($t2,8,2);$i=substr($t2,10,2);$s=substr($t2,12,2);//分离t2 $tt2=mktime($h,$i,$s,$m,$d,$y); return($tt2-$tt1); }; Incoming search terms:php substr 抓空格 (1)

