PHP:DateTime引发带有合法时间戳的异常
我不明白:PHP:DateTime引发带有合法时间戳的异常,php,datetime,Php,Datetime,我不明白: $ts = strval( $this->get_start_date() ); // retrieve (int) timestamp from database $time = new DateTime ( $ts ); // throws an exception: //'DateTime::__construct(): Failed to parse time string //(1346284800) at position 7 (8
$ts = strval( $this->get_start_date() ); // retrieve (int) timestamp from database
$time = new DateTime ( $ts );
// throws an exception:
//'DateTime::__construct(): Failed to parse time string
//(1346284800) at position 7 (8): Unexpected character'
$time = new DateTime();
$time->setTimestamp( $ts );
//works fine
知道这是怎么回事吗?我正在使用
PHP 5.3.10-1ubuntu3.2 with Suhosin-Patch (cli) (built: Jun 13 2012 17:19:58)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies
检查
DateTime的构造函数不等待unix时间戳
,而是使用格式Y-m-dh:i:s
您的第二种方法很好。检查
DateTime的构造函数不等待unix时间戳
,而是使用格式Y-m-dh:i:s
第二种方法很好。要使用UNIX\u时间戳初始化
DateTime
,请在开头使用@:
$time = new DateTime ('@'.$this->get_start_date());
请参阅PHP手册中关于
strotdate()
和DateTime()
接受的格式。要使用UNIX\u时间戳初始化DateTime
,请在开头使用@:
$time = new DateTime ('@'.$this->get_start_date());
请参阅PHP手册中关于strodate()
和DateTime()
接受的格式