我有如下一个字符串,我如何读取它的年、月、日、时、分、秒各是什么。$time="2010-07-26 23:59:59";
//读取出年、月、日、时、分、秒分别各是什么。
请各位指教。

解决方案 »

  1.   

    $date = strtotime($time);echo date('Ymd',$date);
      

  2.   

    $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); //秒
      

  3.   


    //呵呵
    $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
    )
    **/
      

  4.   


    $time = "2010-07-26 23:59:59";
    preg_match_all('/\d+/', $time, $match);
    print_r($match[0]);
    //结果同上
      

  5.   

    可以参考 用 substr() 截取字符串$date = "20100104";  
    $format = substr($date,0,4).'-'.substr($date,4,2).'-'.substr($date,6,2);  
    echo $format;  
      

  6.   


    $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); //秒
      

  7.   

    这么标准的时间字符串当然要用 strtotime
      

  8.   

    在PHP里面时间都是存储的时间戳格式,这样取出来的时候,你需要什么格式的时间你就可以跟方便的操作
    反之如果你你用的是正常的时间格式,你要展现特殊的格式,你可以先strtotime,然后取出你想要的格式
      

  9.   

    为什么都不用现成的函数呢?
    <?php
    $time = "2010-07-26 23:59:59";
    print_r(date_parse($time));
    ?>