PHP Parse Date String

后端 未结 8 1522
春和景丽
春和景丽 2021-01-11 18:14

If I\'ve got a date string:

$date = \"08/20/2009\";

And I want to separate each part of the date:

$m = \"08\";
$d = \"20\";         


        
8条回答
  •  余生分开走
    2021-01-11 19:17

    For internationalized date parsing, see IntlDateFormatter::parse - http://php.net/manual/en/intldateformatter.parse.php

    For example:

    $f = new \IntlDateFormatter('en_gb', \IntlDateFormatter::SHORT, \IntlDateFormatter::NONE);
    $dt = new \DateTime();
    $dt->setTimestamp($f->parse('1/2/2015'));
    

提交回复
热议问题