strtotime只适用于服务器上的默认语言吗?下面的代码应该解析到2005年8月11日,但是它使用了法语的"aout“而不是英语的"aug”。
你知道怎么处理这件事吗?
<?php
$date = strtotime('11 aout 05');
echo date('d M Y',$date);
?>发布于 2011-08-09 05:04:45
从docs
将任何英文文本日期时间描述解析为
时间戳
编辑:六年后的今天,关于为什么strtotime()对于手头的问题是不合适的解决方案成为公认的答案的附注
为了更好地回答实际问题,我想呼应Marc B的答案:尽管票数下降,但date_create_from_format与自定义的月份解释器将提供最可靠的解决方案
但是,目前似乎还没有内置到PHP中的国际日期解析的灵丹妙药。
发布于 2014-05-02 22:53:50
法语月份的日期为:
janvier février mars avril mai juin juillet mai octobre novembre décembre
因此,对于月份用法语表示的非常特殊的情况,您可以使用
function myStrtotime($date_string) { return strtotime(strtr(strtolower($date_string), array('janvier'=>'jan','février'=>'feb','mars'=>'march','avril'=>'apr','mai'=>'may','juin'=>'jun','juillet'=>'jul','août'=>'aug','septembre'=>'sep','octobre'=>'oct','novembre'=>'nov','décembre'=>'dec'))); }如果你用传递$date_string,这个函数无论如何都不会中断,因为它不会做任何替换。
发布于 2014-01-04 02:40:59
如前所述,strtotime不考虑区域设置。但是,您可以使用strptime (请参阅http://ca1.php.net/manual/en/function.strptime.php),因为根据文档:
Month and weekday names and other language dependent strings respect the current locale set with setlocale() (LC_TIME).
请注意,根据您的系统、区域设置和编码,您必须考虑重音字符。
https://stackoverflow.com/questions/6988536
复制相似问题