首页 > php日期 > php 中常用的日期处理函数

php 中常用的日期处理函数

<?php
// date_format2($rs['time'],'%y年%m月%d日%h时%m分%s秒'); 
function date_format2($string, $format='%b %e, %y', $default_date=null) 
{ 
    if (substr(php_os,0,3) == 'win') { 
           $_win_from = array ('%e',  '%t',       '%d'); 
           $_win_to   = array ('%#d', '%h:%m:%s', '%m/%d/%y'); 
           $format = str_replace($_win_from, $_win_to, $format); 
    } 
    if($string != '') { 
        return strftime($format, smarty_make_timestamp($string)); 
    } elseif (isset($default_date) && $default_date != '') { 
        return strftime($format, smarty_make_timestamp($default_date)); 
    } else { 
        return; 
    } 
} 
function smarty_make_timestamp($string){ 
    if(emptyempty($string)) { 
        $string = "now"; 
    } 
    $time = strtotime($string); 
    if (is_numeric($time) && $time != -1) 
        return $time; 
    if (preg_match('/^d{14}$/', $string)) { 
        $time = mktime(substr($string,8,2),substr($string,10,2),substr($string,12,2), 
               substr($string,4,2),substr($string,6,2),substr($string,0,4)); 
 
        return $time; 
    } 
    $time = (int) $string; 
    if ($time > 0) 
        return $time; 
    else 
        return time(); 
}


本文地址:http://www.phprm.com/riqi/fs4179.html

转载随意,但请附上文章地址:-)

标签:php函数 日期处理函数

相关文章

发表留言