读取日期年月日的问题。 我有如下一个字符串,我如何读取它的年、月、日、时、分、秒各是什么。$time="2010-07-26 23:59:59";//读取出年、月、日、时、分、秒分别各是什么。请各位指教。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 $date = strtotime($time);echo date('Ymd',$date); $time="2010-07-26 23:59:59";$t = strtotime($time);echo date('Y', $t); //年echo date('m', $t); //月echo date('d', $t); //日echo date('H', $t); //时echo date('i', $t); //分echo date('s', $t); //秒 //呵呵$time = "2010-07-26 23:59:59";$string = explode('-', str_replace(array(' ', ':'), '-', $time));print_r($string);/**//打印出Array( [0] => 2010 [1] => 07 [2] => 26 [3] => 23 [4] => 59 [5] => 59)**/ $time = "2010-07-26 23:59:59";preg_match_all('/\d+/', $time, $match);print_r($match[0]);//结果同上 可以参考 用 substr() 截取字符串$date = "20100104"; $format = substr($date,0,4).'-'.substr($date,4,2).'-'.substr($date,6,2); echo $format; $time="2010-07-26 23:59:59";$str=strtotime($time);echo date('Y', $str); //年echo date('m', $str); //月echo date('d', $str); //日echo date('H', $str); //时echo date('i', $str); //分echo date('s', $str); //秒 这么标准的时间字符串当然要用 strtotime 在PHP里面时间都是存储的时间戳格式,这样取出来的时候,你需要什么格式的时间你就可以跟方便的操作反之如果你你用的是正常的时间格式,你要展现特殊的格式,你可以先strtotime,然后取出你想要的格式 为什么都不用现成的函数呢?<?php$time = "2010-07-26 23:59:59";print_r(date_parse($time));?> 文章编辑,只更新编辑过的字段,其他的字段不更新 这个算法如何实现,求高手赐教 thinkphp的user 怎么我一刷新就往数据库里添加一条记录啊?大家帮我看看怎么回事? Mysql 错误 Illegal mix of collations..... 一段查询代码多处使用可以吗 有一MYSQL的小问题,怎么得到指定数据的排行。 请求高手相助 我是个初学者连有些技术问题,请各位大侠帮忙看看!!谢谢,谢谢!!! php软件安装程序怎么制作? php+mysql 问题 百度一个星期 竟无人解决 讨论2010年PHP与相关技术情况伤感
$t = strtotime($time);
echo date('Y', $t); //年
echo date('m', $t); //月
echo date('d', $t); //日
echo date('H', $t); //时
echo date('i', $t); //分
echo date('s', $t); //秒
//呵呵
$time = "2010-07-26 23:59:59";
$string = explode('-', str_replace(array(' ', ':'), '-', $time));print_r($string);
/**
//打印出
Array
(
[0] => 2010
[1] => 07
[2] => 26
[3] => 23
[4] => 59
[5] => 59
)
**/
$time = "2010-07-26 23:59:59";
preg_match_all('/\d+/', $time, $match);
print_r($match[0]);
//结果同上
$format = substr($date,0,4).'-'.substr($date,4,2).'-'.substr($date,6,2);
echo $format;
$time="2010-07-26 23:59:59";
$str=strtotime($time);echo date('Y', $str); //年
echo date('m', $str); //月
echo date('d', $str); //日
echo date('H', $str); //时
echo date('i', $str); //分
echo date('s', $str); //秒
反之如果你你用的是正常的时间格式,你要展现特殊的格式,你可以先strtotime,然后取出你想要的格式
<?php
$time = "2010-07-26 23:59:59";
print_r(date_parse($time));
?>