参数: $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($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(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()
这个,你只能把这个读取出来的数据当字符串处理了!!用空格去分解这个字段,保存在数组里,然后提取第一个为月份,第二个为日期,第三个为年份,第四个为小时和分钟,已经上下午
$time = $rs["lastlogin"]
$times = explode(" ",$time)
$month = $times[0]
$day = $times[1]
$year = $times[2]
$hour = substr($times[3],0,2)
$minute = substr($times[3],3,2)
if(substr($times[3],5,1)=='P')
{
$hour = intval($hour)
if($hour<12)
{
$hour += 12
}
}
$realTime = $year."-".$month."-"."day"." ".$hour.":".$minute.":00"
echo $realTime
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)