php时间转换问题

ectwyq 2008-04-22 11:15:35
求教:php如何将时间字符串如:"20080422102312"转换成"2008-04-22-10-23-12"????
...全文
695 点赞 收藏 5
写回复
5 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
thefirstwind 2008-04-22
嗯嗯,以上方法都对,昨天看到一种方法是用
date_format

参考
http://www.php.net/manual/en/function.date-format.php
回复
chenling0828 2008-04-22
给分吧!绝对有效
回复
chenling0828 2008-04-22
告诉你一个最笨方法就是截取字符:
<?php
$time = "20080422120021";
$str1 = substr($time,0,4);
$str2 = substr($time,4,2);
$str3 = substr($time,6,2);
$str4 = substr($time,8,2);
$str5 = substr($time,10,2);
$str6 = substr($time,12,2);
echo ($str1."-".$str2."-".$str3." ".$str4."-".$str5."-".$str6);
?>
回复
laruence 2008-04-22
$date = preg_replace("/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/", "$1-$2-$3-$4-$5-$6", $str);
回复
laruence 2008-04-22
$date = preg_replace("/(\d{4})(\d{2})(\d{2})(\d{2})/", "$1-$2-$3-$4", $str);
回复
相关推荐
发帖
基础编程
创建于2007-09-28

2.1w+

社区成员

从PHP安装配置,PHP入门,PHP基础到PHP应用
申请成为版主
帖子事件
创建了帖子
2008-04-22 11:15
社区公告
暂无公告