我已经建立了一个数据库表,其中包含一个名为“release_date”的 DATETIME 字段,并且模型/资源模型似乎工作正常。但是,我想检索并将“release_date”设置为 Zend_Date 对象。我还想确保它始终以 UTC 格式存储和检索。
您对我如何做到这一点有什么建议,或者有更好的解决方案吗?
最佳答案
你可以在你的资源模型中处理它,像这样:
protected function _beforeSave(Mage_Core_Model_Abstract $object)
{
...
$date = $object->getReleaseDate();
// convert from your server/client timezone to UTC if needed
$object->setReleaseDate($this->formatDate($date));
...
}
protected function _afterLoad(Mage_Core_Model_Abstract $object)
{
...
$date = new Zend_Date($object->getReleaseDate());
// convert to your server/client timezone from UTC if needed
$object->setReleaseDate($date);
...
}
关于php - Magento 1.6 : Using MySQL datetime fields with resource models,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9233768/