dsbo44836129 2013-09-09 10:03
浏览 46
已采纳

从Regional Datetime字符串获取日期

I want to fetch only date: 2013-09-24 from the following string using php:

$2013-09-24T11:53:58+02:00am09pam53119_Tue, 24 Sep 2013 11:53:58 +0200Europe/Berlin58000000Tuesday30[0]

I am getting above string from this line of code:

 $second_date =  date('$first_date[0]', strtotime("+15 days") );

Is there any php built-in function to do this or what can be the simplest way?

  • 写回答

2条回答 默认 最新

  • doulu1914 2013-09-09 10:26
    关注

    If you have that weird string, then just use this

    <?php    
    
    $str = "$2013-09-24T11:53:58+02:00am09pam53119_Tue, 24 Sep 2013 11:53:58 +0200Europe/Berlin58000000Tuesday30[0]";
    $pattern = '/[0-9]{4}-[0-9]{2}-[0-9]{2}/';
    preg_match($pattern, $str, $matches);
    
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?