我有一个函数可以在第一行的文件中读出日期。这个日期的格式是这样的荷兰语2 mei 2013
或28 jun. 2013
它需要将日期字符串转换为时间戳,但无论我尝试什么,它都不适用于mei
飞蛾或任何其他名为月份的荷兰语。这是我目前拥有的代码(原来的函数代码有点多,但这就是出错的地方)
function getTimestamp($date){
date_default_timezone_set('Europe/Amsterdam');
setlocale(LC_ALL, 'nl_NL');
$timestamp = strtotime($date);
return $timestamp;
}
现在,以下是使用此功能时的一些结果:
$timestamp = getTimestamp('28 jun. 2013') //1372370400
$timestamp2 = getTimestamp('2 mei 2013') // false
但是,当我将此代码放入函数中时
echo strftime('%e %b %Y', 1367445600)."\n";
它打印“2 mei 2013”
我如何告诉 php 不仅用荷兰语格式化日期时间字符串,而且用荷兰语读取它?
========================
感谢下面的一些解释,我现在可以运行代码(这是完整的功能)
public function getReportDate(){
$mothsTranslated = array('mrt'=> 'mar','mei'=>'may', 'okt'=>'oct');
$content = file($this->file);
$line = $content[0];
$header = str_getcsv($line, $this->delimiter);
$date = str_replace('.', '', $header[1]);
foreach ($mothsTranslated as $dutch => $eng) {
if(strpos($date, $dutch) !== false){
$date = str_replace($dutch, $eng, $date);
}
}
$timestamp = strtotime($date);
return $timestamp;
}