将德国日期转换为Y-m-d不起作用? [英] Converting a German date to Y-m-d does not work?
问题描述
我想把它转换为2012-02-02,所以我写了这段代码:
$ date ='2。 2012年Februar
$ date = date('Y-m-d',$ date);
$ date var是空的还是1970-01-01之后,什么错误或缺少? / p>
注意:日期是德语格式,所以它不是2月,它的Februar。我从日期选择器得到日期。
谢谢!
您可以使用 * strtotime ,还可以需要在strtotime函数中传递有效的日期格式,因为 $ date
变量没有有效的格式。
您有。
和拼写错误的月份名称。您必须在传递 strtotime
之前清除它们。我已经使用了 str_replace
。
$ date ='2。 2012年Februar
$ date = date('Y-m-d',strtotime(str_replace('Februar','february',str_replace('。'',$ date))))
I have a date like this: 2. Februar 2012
I want to have it converted to 2012-02-02, so I wrote this code:
$date = '2. Februar 2012';
$date = date('Y-m-d', $date);
The $date var is either empty or 1970-01-01 afterwards, whats wrong or missing?
Note: The date is in German format, so its not February, its Februar. I get the date from a date picker that way.
Thanks!
You can use *strtotime and also need to pass the valid date format in strtotime function as your $date
variable is not having valid format.
You have .
and misspelled month name. You have to clear those before passing in strtotime
. I have used str_replace
for this.
$date = '2. Februar 2012';
$date = date('Y-m-d', strtotime(str_replace('Februar','february',str_replace('.','', $date))));
这篇关于将德国日期转换为Y-m-d不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!