Magento前端,客户订单列表中,只显示下单日期,而没有订单时间,在某些情况下,这有点不妥,客户希望看到下单时间。看了下Magento代码,修改起来很容易。

Magento有个日期时间格式化函数formatDate,位于app/code/core/Mage/Core/Helper/Data.php中。

    /**
     * Date and time format codes
     */
    const FORMAT_TYPE_FULL  = 'full';
    const FORMAT_TYPE_LONG  = 'long';
    const FORMAT_TYPE_MEDIUM= 'medium';
    const FORMAT_TYPE_SHORT = 'short';
    
    /**
     * Format date using current locale options
     *
     * @param   date|Zend_Date|null $date in GMT timezone
     * @param   string $format
     * @param   bool $showTime
     * @return  string
     */
    public function formatDate($date=null, $format='short', $showTime=false)
    {
        if (Mage_Core_Model_Locale::FORMAT_TYPE_FULL    !==$format &&
            Mage_Core_Model_Locale::FORMAT_TYPE_LONG    !==$format &&
            Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM  !==$format &&
            Mage_Core_Model_Locale::FORMAT_TYPE_SHORT   !==$format) {
            return $date;
        }
        if (!($date instanceof Zend_Date) && $date && !strtotime($date)) {
            return '';
        }
        if (is_null($date)) {
            $date = Mage::app()->getLocale()->date(Mage::getSingleton('core/date')->gmtTimestamp(), null, null);
        }
        elseif (!$date instanceof Zend_Date) {
            $date = Mage::app()->getLocale()->date(strtotime($date), null, null, $showTime);
        }

        if ($showTime) {
            $format = Mage::app()->getLocale()->getDateTimeFormat($format);
        }
        else {
            $format = Mage::app()->getLocale()->getDateFormat($format);
        }

        return $date->toString($format);
    }

前端客户订单日期,是由模板文件template/sales/order/recent.phtml来控制的。只需要把:

echo $this->formatDate($_order->getCreatedAtStoreDate())

修改为:

echo $this->formatDate($_order->getCreatedAtStoreDate(), 'medium', true)

当然,你可以尝试下full或者long格式。