是我的问题还是PHP的DateTime有一个bug


Is it me or there's a bug in PHP DateTime?

我刚刚遇到了一个我从未想过会存在的问题。我有一个表格,以以下格式04/28/2013 11:00提交日期。在用户前端,我使用jquery datetimepicker和后端,我有php来处理表单。

做一些测试,我发现DateTime在php不抛出异常时,时间被打破。例如,这个04/28/2013 11:00123123不会触发异常-相反,DateTime返回now时间。在我的例子中,日期与now无关-这是一个特定的日期&未来的时间。

在我看来DateTime应该返回一个异常而不是now时间。是我的问题,还是有问题?

编辑:我使用php 5.3.23

将此作为回复,因为评论不适合。

<?php
new DateTime('04/28/2013 11:00123123');

我:

Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (04/28/2013 11:00123123) at position 16 (1): Double time specification' in ...
Exception: DateTime::__construct(): Failed to parse time string (04/28/2013 11:00123123) at position 16 (1): Double time specification in ...
Call Stack:
    0.0001     635184   1. {main}() 
    0.0001     636048   2. DateTime->__construct() 

我使用的是PHP5.3.10。你呢?

相关文章: