首页 | 注册 | 登录 | 归档 | 搜索 | 标签 | 在线工具

PHP的日期时间格式化函数

函数名:date_format
参数: $string 时间源,可以是2006-04-24 09:56:07这种格式,$format要格式化的形式,如%Y年%m月%d日%H时%M分%S秒看需要删改
示例:<?php
echo date_format($rs['time'],'%Y年%m月%d日%H时%M分%S秒');
?>

function date_format($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($formatsmarty_make_timestamp($string));
     } elseif (isset(
$default_date) && $default_date != '') {
             return 
strftime($formatsmarty_make_timestamp($default_date));
     } else {
             return;
     }
}


function 
smarty_make_timestamp($string)
{
     if(empty(
$string)) {
             
$string "now";
     }
     
$time strtotime($string);
     if (
is_numeric($time) && $time != -1)
             return 
$time;


     
// is mysql timestamp format of YYYYMMDDHHMMSS?
     
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;
     }


     
// couldn't recognize it, try to return a time
     
$time = (int) $string;
     if (
$time 0)
             return 
$time;
     else
             return 
time();
}

Tags: php

Address: http://www.amxku.net/php-time/

上一篇 »» PHP 服务器变量:$_SERVER
下一篇 »» Sebug.net正式版 上线

相关文章

发表评论

评论内容: