在 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 - 这是前一天而不是预期的......
任何帮助或提示表示赞赏。先感谢您!