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.txt
1 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)
本文永久链接地址: http://www.cngry.com/archives/php-calculate-time-difference.html
本文短网址:http://gry.im/431
转载请注明: 转载自gry's blog
如果你觉得本博内容不错,欢迎 [订阅 gry's blog],以便第一时间了解本博更新内容!


沙发空缺中,还不快抢!