我刚刚遇到了一个我从未想过会存在的问题。我有一个表格,以以下格式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。你呢?