2011-10-18 20 views
1

我想在Magento日曆中顯示時間。爲此,我按照this url的說明進行了操作。我如何在magento的日曆中顯示時間?

$this->getTime() ? 'true' : 'false', 

這樣::

首先我必須改變這種修改date.php

$this->getTime() ? 'true' : 'true', 

然後,我已經改變了

$displayFormat = Varien_Date::convertZendToStrFtime($outputFormat, true, (bool)$this->getTime()); 

$displayFormat = Varien_Date::convertZendToStrFtime($outputFormat = Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT)); 

然後我已經更新了en.xml文件,從:

<dateFormatLength type="short"> 
    <dateFormat> 
     <pattern>M/d/yy</pattern> 
    </dateFormat> 
</dateFormatLength> 

到:

<dateFormatLength type="short"> 
    <dateFormat> 
     <pattern>M/d/yy h:mm a</pattern> 
    </dateFormat> 
</dateFormatLength> 

一切工作正常,但我得到一個奇怪的錯誤;現在,當我點擊日曆圖標並更改值時,輸入框中的值顯示爲10/10/11 02:10 PM 02:10 PM。我該如何解決這個錯誤?

+0

如何,這是一個錯誤,什麼是你正在尋找正確的輸出? –

+0

我在尋找這10/10/11 02:10 PM.But現在我得到10/10/11 02:10 PM 02:10 PM.Time顯示兩次 – mjdevloper

+0

您不應該更改en.xml文件或任何核心文件,它都是一個不需要編輯的框架文件。您必須使用框架方法和類來獲取正確的日期時間格式。 你爲什麼改變這些文件?論壇帖子已經很好:http://www.magentocommerce.com/boards/viewreply/171494/只需將Mage_Core_Model_Locale :: FORMAT_TYPE_MEDIUM替換爲Mage_Core_Model_Locale :: FORMAT_TYPE_SHORT –

回答

4

下面是一個例子來獲得與日期時間日曆場,對Magento的1.4及以上的測試:

public function getHtmlDateStartOptions($product = null) 
    { 
    $configValue = $this->getProduct()->getPreconfiguredValues()->getData('subscription_date_start'); 
    $dateStrFormat = Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT); 

    $dateStartId = 'subscription_date_start'; 
    $form = new Varien_Data_Form(); 
    $element = $form->addField($dateStartId, 'date', array(
     'name'  => $dateStartId, 
     'style'  => 'width:100px', 
     'image' => $this->getSkinUrl('images/grid-cal.gif'), 
     'format' => $dateStrFormat, 
     'no_span' => true, 
     'time' => true, 
    )); 

    $element->setValue($configValue, $dateStrFormat);// date format must be defined here too, don't remove 
    return $form->toHtml(); 
} 
相關問題