在您的情况下,我将使用一个简单的翻译数组将意大利月份名称转换为英文月份名称。像这样的东西应该工作: -
/**
* @param $dateStr
* @return DateTime
*/
function getDateFromItalian($dateStr)
{
$translation = array(
'gennaio' => 'January',
'febbraio' => 'February',
'marzo' => 'March',
'aprile' => 'April',
'maggio' => 'May',
'giugno' => 'June',
'luglio' => 'July',
'agosto' => 'August',
'settembre' => 'September',
'ottobre' => 'October',
'novembre' => 'November',
'dicembre' => 'December',
'gen' => 'January',
'feb' => 'February',
'mar' => 'March',
'apr' => 'April',
'mag' => 'May',
'giu' => 'June',
'lug' => 'July',
'ago' => 'August',
'set' => 'September',
'ott' => 'October',
'nov' => 'November',
'dic' => 'December',
);
list($day, $month, $year) = explode('/', $dateStr);
return new \DateTime($day . ' ' . $translation[strtolower($month)] . ' ' . $year, new \DateTimeZone('Europe/Rome'));
}
var_dump(getDateFromItalian('01/lug/2013'));
输出:-
object(DateTime)[1]
public 'date' => string '2013-07-01 00:00:00' (length=19)
public 'timezone_type' => int 3
public 'timezone' => string 'Europe/Rome' (length=11)
有关详细信息,请参阅PHP DateTime 手册。