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)

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:

本文永久链接地址: http://www.cngry.com/archives/php-calculate-time-difference.html

本文短网址:http://gry.im/431

转载请注明: 转载自gry's blog

如果你觉得本博内容不错,欢迎 [订阅 gry's blog],以便第一时间了解本博更新内容!

前一篇: 
后一篇:

沙发空缺中,还不快抢!

可用XHTML标签: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

(吐) (难过) (酷) (谄笑) (调皮) (色) (脸红) (给力) (笑) (睡觉) (生病) (生气) (烧香) (淘气) (流口水) (汗) (晕) (惊恐) (微笑) (尴尬) (大笑) (困) (囧) (哭) (吃饭) (口罩) (压力) (冷) (住嘴) (书呆子) (不给力) (不)

Twitter
Feed