在PHP中,如何将日期转换为数字格式,而不事先知道字符串的格式?

sto*_*ist 0 php date

我需要做的翻译的例子:

$stringDate = "November 2009";  $output = "11/09";
$stringDate = "October 1 2010"; $output = "10/01/2010";

$stringDate = "January 2010"; $output = "01/10";
$stringDate = "January 9 2010"; $output = "01/09/2010";
Run Code Online (Sandbox Code Playgroud)

请注意,我不知道$ stringDate将采用哪种格式,并且在月份日设置中缺少逗号.

感谢任何人提供的任何帮助.

Kem*_*emo 9

PHP.net strtotime

首先使用strtotime将其转换为UNIX时间戳,然后使用date()函数将其转换为您自己的格式.