从字符串创建新的日期时间 [英] Creating new Date Time from string
本文介绍了从字符串创建新的日期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个字符串'23/05/2013',我想以此创建一个新的Date Time对象,所以我这样做了:
I have a string which is '23/05/2013' and I wanted to create a new Date Time object from this, so I did:
new \DateTime('23/05/2013');
任何想法为什么我总是会收到此错误:
Any idea why I am getting this error all the time:
DateTime::__construct(): Failed to parse time string (23/05/2013) at position 0 (2): Unexpected character
推荐答案
It's mm/dd/yyyy, which is American, not British
使用
DateTime::createFromFormat('d/m/Y', '23/05/2013');
这篇关于从字符串创建新的日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文