我有一个日期字符串,我想将其转换为数字。字符串看起来像
Dienstag, 30. Oktober 2012
以及我一直在尝试使用的代码
date('Y.m.d' , strtotime($str[4]));
每次返回1970.01.01
您可以通过更改当前区域设置来实现这一点 http://php.net/manual/bg/function.setlocale.php 如果您知道源日期格式,您也可以坚持使用http://bg2.php.net/ date_create_from_format
以下是有关使用不同语言的相同问题strtotime 的更多详细信息?
strtotime
采用英语字符串。查看可能的日期/时间格式
使用 strtotime() 将日期转换为时间戳
$ts = strtotime('2007 年 12 月 21 日'); 回显日期('Ymd',$ts);
<?php
setlocale(LC_ALL, 'fr_FR');
$str= 'Dienstag, 30. Oktober 2012';
echo date('Y.m.d' , strtotime($str[4]));
?>