gpt4 book ai didi

php - Magento 1.6 : Using MySQL datetime fields with resource models

转载 作者:可可西里 更新时间:2023-11-01 07:35:49 24 4
gpt4 key购买 nike

我已经建立了一个数据库表,其中包含一个名为“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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com