Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试从以下字符串创建 DateTime:
2012-02-16 00:45:54.441899
我尝试使用这种格式,但没有成功:
Ymd H:i:s.*
我能做些什么?我不在乎点之后的部分。
您忘记了格式的微秒部分:
$s = '2012-02-16 00:45:54.441899'; $d = DateTime::createFromFormat('Y-m-d H:i:s.u', $s);//format looks like your string echo $d->format('Ymd');//output format can be whatever you like