【发布时间】:2015-05-10 02:51:09
【问题描述】:
我一直在尝试在 CodeIgniter 中构造一个DateTime object。我正在从库中加载它。但我似乎无法用给定的 $time_zone 参数构造 DateTime() 。
我能看到这种情况的唯一方法是在所有方法中添加 DateTime 对象。
这是使用 mvc 的一大缺点。有没有人有替代方案?
我的代码:
class Create_Timestamp
{
private $date_time;
/**
* @param $time_zone : gets passed in from a cookie. Cookie value is an array that gets retrieved from the DB. In the
* array there time zone value
* @return int
*/
public function __construct($time_zone)
{
$this->date_time = new DateTime("now", new DateTimeZone($time_zone));
}
public function TimeStamp()
{
$time_stamp = $this->date_time->getTimestamp();
return $time_stamp;
}
public function convertTimeStamp($unix_time_stamp)
{
fb($unix_time_stamp);
$this->date_time->createFromFormat("m/d/Y", $unix_time_stamp);
//$this->date_time->setTimestamp($unix_time_stamp);
$formatted_time_stamp = $this->date_time->format("m/d/Y h:i:s A");
return $formatted_time_stamp;
}
}
【问题讨论】:
-
请记住格式化您的代码。
标签: php codeigniter datetime