2016-08-05 113 views
0

我在magento的前端發現錯誤的博客發佈日期。錯誤的博客發佈日期顯示在Magento

這是我的帖子的phtml文件的代碼。

$formatType = Mage::getStoreConfig(NeoTheme_Blog_Helper_Data::XPATH_CONFIG_DATETIME_FORMAT_TYPE); 
$format = ($formatType != 'custom')? 
    Mage::app()->getLocale()->getDateTimeFormat($formatType): 
    Mage::getStoreConfig(NeoTheme_Blog_Helper_Data::XPATH_CONFIG_DATETIME_CUSTOM_FORMAT); 

,並在下面HTML它顯示日期一樣 -

<span class="post-time"> 
       <?php //echo $this->__('Posted On: '); ?> 
       <?php $date = ($this->getPost()->getPostDate() != NULL)? $this->getPost()->getPostDate() : $this->getPost()->getCreatedAt(); ?> 
       <?php echo Mage::app()->getLocale()->date($date)->toString($format); ?> 
       <?php // $timestamp = (int) Mage::app()->getLocale()->date($date)->getTimestamp() ;?> 
       <?php // echo date('d D', $timestamp)?><?php // echo date('M', $timestamp)?> 
      </span> 

這是我的數據庫結構

+--------------------+----------------------+------+-----+---------------------+-----------------------------+ 
| Field    | Type     | Null | Key | Default    | Extra      | 
+--------------------+----------------------+------+-----+---------------------+-----------------------------+ 
| entity_id   | int(10) unsigned  | NO | PRI | NULL    | auto_increment    | 
| created_at   | timestamp   | NO |  | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP | 
| updated_at   | timestamp   | NO |  | 0000-00-00 00:00:00 |        | 
| status    | smallint(5) unsigned | NO |  | 1     |        | 
| title    | text     | NO |  | NULL    |        | 
| author    | text     | NO |  | NULL    |        | 
| post_date   | timestamp   | NO |  | 0000-00-00 00:00:00 |        | 
| summary   | text     | NO |  | NULL    |        | 
| content_html  | text     | NO |  | NULL    |        | 
| meta_description | text     | YES |  | NULL    |        | 
| meta_title   | text     | YES |  | NULL    |        | 
| meta_keywords  | text     | YES |  | NULL    |        | 
| store_ids   | text     | NO |  | NULL    |        | 
| category_ids  | text     | NO |  | NULL    |        | 
| tag_ids   | text     | NO |  | NULL    |        | 
| cms_identifier  | varchar(255)   | YES | UNI | NULL    |        | 
| customer_group_ids | text     | YES |  | NULL    |        | 
| publish_date  | timestamp   | YES |  | NULL    |        | 
| use_summary  | smallint(6)   | YES |  | 1     |        | 
| root_template  | varchar(255)   | YES |  | NULL    |        | 
| layout_update_xml | text     | YES |  | NULL    |        | 
+--------------------+----------------------+------+-----+---------------------+-----------------------------+ 

誰能幫我找到什麼是錯,此代碼。 在數據庫中顯示正確的日期。

+0

你檢查你的本地設置的時間在'系統>配置區域設置選項>一般本地option'它是正確的 –

+0

是的,它是按照我的理解EST時區(美國紐約) –

+0

在數據庫中保存正確'EST時區(美國紐約)'? –

回答

0

有兩件事你必須

先上更新CURRENT_TIMESTAMP刪除此所以,如果你想要做的Magento方式的日期將不會更新

使用此爲created_At Varien_Date::now()設定值。

<?php $date=Mage::app()->getLocale()->date($date); 
     echo date('L d, M Y',strtotime($date)) ?> 
+0

如何轉換此日期'<?php echo Mage :: app() - > getLocale() - > date($ date); ?> 2015年12月22日上午12:48:42'喜歡這個'2016年7月14日星期四' –

+0

更新了答案 –

+0

它什麼也沒有顯示。當我添加你的代碼時,實際上頁面什麼也沒有顯示我寫了這個代碼'<?php echo Mage :: helper('core') - > formatDate($ date,Mage_Core_Model_Locale :: FORMAT_TYPE_FULL,false); ?>'但它顯示這樣的輸出'2015年12月22日星期二'如何更改爲'2015年12月22日星期二' –