php字符串到时间问题

时间:2012-11-27 09:01:51

标签: php date

我有一个日期字符串,我想用数字转换。字符串看起来像

Dienstag, 30. Oktober 2012

以及我尝试使用的代码

date('Y.m.d' , strtotime($str[4]));
每次1970.01.01

都会返回

4 个答案:

答案 0 :(得分:2)

您可以通过更改当前区域设置 http://php.net/manual/bg/function.setlocale.php来实现此目的 如果您知道源日期格式,您也可以坚持使用http://bg2.php.net/date_create_from_format

以下是有关同一问题strtotime With Different Languages?

的更多详细信息

答案 1 :(得分:1)

strtotime以英语填充字符串。查看可能的date/time formats

答案 2 :(得分:0)

使用strtotime()将日期转换为时间戳

$ ts = strtotime('2007年12月21日'); 回音日期('Y-m-d',$ ts);

答案 3 :(得分:0)

<?php
setlocale(LC_ALL, 'fr_FR');
$str= 'Dienstag, 30. Oktober 2012';

echo date('Y.m.d' , strtotime($str[4]));   
?>