This question already has an answer here:
这个问题已经有了答案:
- Convert one date format into another in PHP 14 answers
- 将一个日期格式转换为另一个PHP 14答案
I have date in format like 23:44 01.03.2016, I need to format it to: Y-m-d H:i:s
.
我有日期的格式,如:23:44 01.03.2016,我需要把它格式化为:Y-m-d H: I:s。
Here is what I try:
以下是我的尝试:
$article_date = strtotime($date);
$article_date2 = date('Y-m-d H:i:s',$article_date);
where $date is 23:44 01.03.2016.
其中$date为23:44 01.03.2016。
The code returns 1970-01-01 01:00:00
. I've also tried different dates, similar outcome. How to solve this?
代码返回1970-01-01 01:00:00。我也尝试过不同的日期,相似的结果。如何解决呢?
Thanks!
谢谢!
1 个解决方案
#1
0
Maybe you can try this:
也许你可以试试这个:
$date = new DateTime('23:44 01.03.2016');
echo $date->format('Y-m-d H:i:s');
for more details on the object DateTime check this
有关对象DateTime的更多细节,请查看此文档
#1
0
Maybe you can try this:
也许你可以试试这个:
$date = new DateTime('23:44 01.03.2016');
echo $date->format('Y-m-d H:i:s');
for more details on the object DateTime check this
有关对象DateTime的更多细节,请查看此文档