首页 > 语言 > PHP > 正文

php 中常用的日期处理函数

2024-09-04 11:45:34
字体:大 中 小
来源:转载
供稿:网友
  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. } 

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表