【发布时间】:2013-04-18 06:26:19
【问题描述】:
我想从负 UNIX 时间戳(1970 年之前)创建 PHP \DateTime 对象,微秒级,没有太多脏代码。
new \DateTime("@-100") 有效,但 new \DateTime("@-100.123") 无效。
\DateTime::createFromFormat("U u", "100 123456") 有效,但 \DateTime::createFromFormat("U u", "-100 123456") 无效。
并且 \DateInterval 当前没有微秒。
到目前为止,我发现创建此类 DateTime 的唯一方法是解析 new \DateTime("1969-12-31T23:59:59.877GMT") 之类的字符串,但我不喜欢 number->string->DateTime 链。有没有更明确的方法?
【问题讨论】: