DateTime :: createFromFormat()在简单的例子上失败 [英] DateTime::createFromFormat() fails on simple example

查看:103
本文介绍了DateTime :: createFromFormat()在简单的例子上失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个输出是'无效的日期格式'。我做错了什么?

The output of this is 'invalid date format'. What am I doing wrong?

$startTimestamp = DateTime::createFromFormat("YYYY-mm-dd","2014-07-25");
if (FALSE===$startTimestamp) {
  die('invalid date format');
}


推荐答案

您使用的是错误的日期标识符。需要一个 Y m d

You're using the wrong date identifiers. Just one Y, m, and d are needed:

$startTimestamp = DateTime::createFromFormat("Y-m-d","2014-07-25");

这篇关于DateTime :: createFromFormat()在简单的例子上失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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