Magento的formatDate助手打印错误的日期

时间:2012-12-25 10:38:49

标签: templates magento date helper

在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

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

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

1 个答案:

答案 0 :(得分:0)

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