php - mktime还是strtotime?

n00*_*101 4 php strtotime mktime

我正试图将2010-02转换为2010年2月.但是,我一直持续到1969年12月

我尝试过使用mktime,strtotime和两者的某种组合,但仍然无法做到......

这是我最近尝试过的......

$path_title = date('F, Y', mktime(0,0,0,2,0,2010));
Run Code Online (Sandbox Code Playgroud)

dec*_*eze 8

这将是一种方法:

$dateString = '2010-02';
list($year, $month) = explode('-', $dateString);
$timeStamp = mktime(0, 0, 0, $month, 1, $year);
echo date('F, Y', $timestamp);
Run Code Online (Sandbox Code Playgroud)

另一种方式是:

$dateString = '2010-02';
$timestamp = strtotime($dateString . '-01');
echo date('F, Y', $timestamp);
Run Code Online (Sandbox Code Playgroud)

strtotime 无法处理像"2010-02"这样的模棱两可的日期,但是如果你把它作为一个完整的日期它应该工作.

否则,您可能想要查看类似的内容DateTime::createFromFormat.