magento中把本地日期格式转换为国际日期格式

来源:互联网 发布:手机淘宝查看历史评价 编辑:程序博客网 时间:2024/04/30 14:40

来自magento的文件:



Mage::app()->getLocale()->date($creditMemo->getCreatedAt())->toString('YYYY-MM-dd');

或:

//$data为数组,date_expires为数组中要格式化日期的key
$this->_filterDates($data, array('date_expires'));

    protected function _filterDates($array, $dateFields)
    {
        if (empty($dateFields)) {
            return $array;
        }
        $filterInput = new Zend_Filter_LocalizedToNormalized(array(
            'date_format' => Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT)
        ));
        $filterInternal = new Zend_Filter_NormalizedToLocalized(array(
            'date_format' => Varien_Date::DATE_INTERNAL_FORMAT
        ));

        foreach ($dateFields as $dateField) {
            if (array_key_exists($dateField, $array) && !empty($dateField)) {
                $array[$dateField] = $filterInput->filter($array[$dateField]);
                $array[$dateField] = $filterInternal->filter($array[$dateField]);
            }
        }
        return $array;
    }


原创粉丝点击