【问题标题】:Magento's formatDate helper prints incorrect dateMagento 的 formatDate 助手打印不正确的日期
【发布时间】:2012-12-25 10:38:49
【问题描述】:

在 Magento 模板中,我选择了存储为产品属性的日期。这就是配置(设置资源):

# Attribute default config - every property can be overridden
$defaultAttributeConfig = array(
    'input'                     => 'date',
    'type'                      => 'datetime',
    'backend'                   => 'eav/entity_attribute_backend_datetime',
    'frontend'                  => 'eav/entity_attribute_frontend_datetime',
    'visible'                   => true,
    'visible_on_front'          => false,
    'required'                  => false,
    'user_defined'              => false,
    'used_in_product_listing'   => true,
    'group'                     => $defaultAttributeGroup,
    'global'                    => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
    'apply_to'                  => 'bundle,simple,configurable',
    # Other
    'default'                    => null,
    'source'                     => null,
    'searchable'                 => false,
    'visible_in_advanced_search' => false,
    'filterable'                 => false,
    'filterable_in_search'       => false,
    'comparable'                 => false,
    'is_html_allowed_on_front'   => true,
    'is_configurable'            => false,
    'used_for_sort_by'           => false,
    'position'                   => 0,
    'used_for_promo_rules'       => false,
);

$installer->addAttribute(
    $productEntityTypeId,
    'time_lapse_begin',
    array_merge($defaultAttributeConfig, array(
        'label'     => 'Time-lapse begin',
        'sort'      => 10,
    ))
);

在我的模板文件中,我正在处理日期以进行如下调试:

<?php list($timeLapseBegin, $timeLapseEnd) = array($_product->getTimeLapseBegin(), $_product->getTimeLapseEnd()); ?>

<?php if ($this->validateDate($timeLapseBegin)): ?>

<p>
    Origin Date <?php echo $timeLapseBegin ?><br />
    Full Date: <?php echo Mage::helper('core')->formatDate($timeLapseBegin, 'full'); ?><br />
    Long Date: <?php echo Mage::helper('core')->formatDate($timeLapseBegin, 'long'); ?><br />
    Medium Date: <?php echo Mage::helper('core')->formatDate($timeLapseBegin, 'medium'); ?><br />
    Short Date: <?php echo Mage::helper('core')->formatDate($timeLapseBegin, 'short'); ?>
</p>

<?php endif; ?>

很遗憾,输出不如预期:

Origin Date 2013-01-01 00:00:00
Full Date: Montag, 31. Dezember 2012
Long Date: 31. Dezember 2012
Medium Date: 31.12.2012
Short Date: 31.12.12

如您所见,Origin Date 为 2013/01/01,但 Magento 的助手将其格式化为 2012/12/31 - 这是前一天,而不是预期...

感谢任何帮助或提示。提前谢谢!

【问题讨论】:

  • 点击编辑将其发布到问题中...您有责任明确说明您的问题..
  • 刚刚找到解决方案 - 我错过了将时区设置为正确的值... :)
  • 我在这里找到了另一个解决方案:stackoverflow.com/a/12222444/444395

标签: templates magento date helper


【解决方案1】:
Mage::app()->getLocale()->date($data['start_date'], Zend_Date::DATE_SHORT, null, false);

将“useTimezone”设置为 False

Magento custom module date field saving date to one day before the selected date

【讨论】:

    猜你喜欢
    • 2019-06-18
    • 2020-06-26
    • 2014-09-29
    • 1970-01-01
    • 1970-01-01
    • 2016-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多