Date 在Magento中显示产品更新日期
我想在Magento产品页面中显示上次更新的日期(不是创建日期)Date 在Magento中显示产品更新日期,date,magento,product,Date,Magento,Product,我想在Magento产品页面中显示上次更新的日期(不是创建日期) <?php echo $_product->getUpdatedAt();?> IS WORKING 正在工作 但我不想显示时间,只想显示日期 可能吗 Magento将updatedAt属性存储为mysql时间戳。您只需要使用普通的PHP日期函数来显示日期部分 e、 g 没有专门的magento函数,只有简单的PHP,虽然您可以使用一些内置的locale方法来显示用户时区的正确日期,但同样,这可以使用老式的P
<?php echo $_product->getUpdatedAt();?> IS WORKING
正在工作
但我不想显示时间,只想显示日期
可能吗 Magento将updatedAt属性存储为mysql时间戳。您只需要使用普通的PHP日期函数来显示日期部分 e、 g
没有专门的magento函数,只有简单的PHP,虽然您可以使用一些内置的locale方法来显示用户时区的正确日期,但同样,这可以使用老式的PHP来完成。Ashley的解决方案应该可以工作,但您可能必须先将其包装起来 我建议使用Magento的日期模型来获取时区中的时间(它还将考虑您的时间戳) 看看
app/code/core/Mage/core/Model/Date.php
<?php
class Mage_Core_Model_Date
{
/**
* Converts input date into date with timezone offset
* Input date must be in GMT timezone
*
* @param string $format
* @param int|string $input date in GMT timezone
* @return string
*/
public function date($format = null, $input = null)
{
if (is_null($format)) {
$format = 'Y-m-d H:i:s';
}
$result = date($format, $this->timestamp($input));
return $result;
}
/**
* Converts input date into timestamp with timezone offset
* Input date must be in GMT timezone
*
* @param int|string $input date in GMT timezone
* @return int
*/
public function timestamp($input = null)
{
if (is_null($input)) {
$result = $this->gmtTimestamp();
} else if (is_numeric($input)) {
$result = $input;
} else {
$result = strtotime($input);
}
$date = Mage::app()->getLocale()->date($result);
$timestamp = $date->get(Zend_Date::TIMESTAMP) + $date->get(Zend_Date::TIMEZONE_SECS);
unset($date);
return $timestamp;
}
}
代码echo Mage::getModel('core/date')->date(“Y-m-d”,$\u product->getUpdatedAt());做得很好!非常感谢:)这个答案完全错了。1.这和2有Magento功能性。mysql时间戳与UNIX时间戳不同,UNIX时间戳由date()使用
echo date("Y-m-d", strtotime($_product->getUpdatedAt()));
echo Mage::getModel('core/date')->date("Y-m-d", $_product->getUpdatedAt());
<?php
class Mage_Core_Model_Date
{
/**
* Converts input date into date with timezone offset
* Input date must be in GMT timezone
*
* @param string $format
* @param int|string $input date in GMT timezone
* @return string
*/
public function date($format = null, $input = null)
{
if (is_null($format)) {
$format = 'Y-m-d H:i:s';
}
$result = date($format, $this->timestamp($input));
return $result;
}
/**
* Converts input date into timestamp with timezone offset
* Input date must be in GMT timezone
*
* @param int|string $input date in GMT timezone
* @return int
*/
public function timestamp($input = null)
{
if (is_null($input)) {
$result = $this->gmtTimestamp();
} else if (is_numeric($input)) {
$result = $input;
} else {
$result = strtotime($input);
}
$date = Mage::app()->getLocale()->date($result);
$timestamp = $date->get(Zend_Date::TIMESTAMP) + $date->get(Zend_Date::TIMEZONE_SECS);
unset($date);
return $timestamp;
}
}