将德国日期转换为Y-m-d不起作用? [英] Converting a German date to Y-m-d does not work?

查看:98
本文介绍了将德国日期转换为Y-m-d不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个这样的日期:2. Februar 2012



我想把它转换为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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆