网站地图    收藏   

主页 > php专栏 > php日期 >

php 中常用的日期处理函数 - php日期

来源:自学PHP网    时间:2014-11-30 11:50 作者: 阅读:次

[导读] date_format2($rs[ 39;time 39;], 39;%y年%m月%d日%h时%m分%s秒 39;);functiondate_format2($string,$format= 39;%b%e,%y 39;,$default_date=null){if(substr(php教程_os,0,3)== 39;win...

php 中常用的日期处理函数

  1. // date_format2($rs['time'],'%y年%m月%d日%h时%m分%s秒'); 
  2. function date_format2($string, $format='%b %e, %y', $default_date=null) 
  3. { 
  4.     if (substr(php教程_os,0,3) == 'win') { 
  5.            $_win_from = array ('%e',  '%t',       '%d'); 
  6.            $_win_to   = array ('%#d', '%h:%m:%s', '%m/%d/%y'); 
  7.            $format = str_replace($_win_from, $_win_to, $format); 
  8.     } 
  9.     if($string != '') { 
  10.         return strftime($format, smarty_make_timestamp($string)); 
  11.     } elseif (isset($default_date) && $default_date != '') { 
  12.         return strftime($format, smarty_make_timestamp($default_date)); 
  13.     } else { 
  14.         return; 
  15.     } 
  16. } 
  17. function smarty_make_timestamp($string){ 
  18.     if(emptyempty($string)) { 
  19.         $string = "now"; 
  20.     } 
  21.     $time = strtotime($string); 
  22.     if (is_numeric($time) && $time != -1) 
  23.         return $time; 
  24.     if (preg_match('/^d{14}$/', $string)) { 
  25.         $time = mktime(substr($string,8,2),substr($string,10,2),substr($string,12,2), 
  26.                substr($string,4,2),substr($string,6,2),substr($string,0,4)); 
  27.  
  28.         return $time; 
  29.     } 
  30.     $time = (int) $string; 
  31.     if ($time > 0) 
  32.         return $time; 
  33.     else 
  34.         return time(); 
  35. } 

自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习

京ICP备14009008号-1@版权所有www.zixuephp.com

网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com

添加评论