开发杂记-烦心整理

by kevin 11. 十一月 2014 21:10 >

chown命令:

可以用来改变linux文件的所有者,用到这个,是因为交替使用ftp和winscp上传文件,而且使用了不同的用户,导致经常出现上传失败。尴尬

css的 line-height:

很多浏览器默认line-height的值是font-size的120%,也有是100%的,所有应该考虑reset一下。

php的日期比较:

过程化方法:date_diff

对象化方法:DateTimeObject->diff

这个没有.net那么舒服,有个TimeSpan,要获取相差多少天,多少秒的,真心麻烦。

直接上代码:

   1: public static function datediff($dt_menor, $dt_maior, $str_interval, $relative=false) {
   2:     if (is_string($dt_menor))
   3:         $dt_menor = date_create($dt_menor);
   4:     if (is_string($dt_maior))
   5:         $dt_maior = date_create($dt_maior);
   6:  
   7:     $diff = date_diff($dt_menor, $dt_maior, !$relative);
   8:  
   9:     switch ($str_interval) {
  10:         case "y":
  11:             $total = $diff->y + $diff->m / 12 + $diff->d / 365.25;
  12:             break;
  13:         case "m":
  14:             $total = $diff->y * 12 + $diff->m + $diff->d / 30 + $diff->h / 24;
  15:             break;
  16:         case "d":
  17:             $total = $diff->y * 365.25 + $diff->m * 30 + $diff->d + $diff->h / 24 + $diff->i / 60;
  18:             break;
  19:         case "h":
  20:             $total = ($diff->y * 365.25 + $diff->m * 30 + $diff->d) * 24 + $diff->h + $diff->i / 60;
  21:             break;
  22:         case "i":
  23:             $total = (($diff->y * 365.25 + $diff->m * 30 + $diff->d) * 24 + $diff->h) * 60 + $diff->i + $diff->s / 60;
  24:             break;
  25:         case "s":
  26:             $total = ((($diff->y * 365.25 + $diff->m * 30 + $diff->d) * 24 + $diff->h) * 60 + $diff->i) * 60 + $diff->s;
  27:             break;
  28:     }
  29:     if ($diff->invert)
  30:         return -1 * $total;
  31:     else
  32:         return $total;
  33: }
分享到: 更多

打赏请我喝果汁咯

支付宝 微信

关于我

80后,单身,平庸的程序员。

喜欢看书,乐于交友,向往旅游。

遇建Kevin

FluentData交流群:477926269

Fluentdata