magento datetime

piaoling  2011-08-05 10:39:55

Are you using date-time functions (date(), time(),now(), etc) directly inside magento ??? Think twice man !!!

Even though time is set properly in you server or you set right timezone in your php.ini file, you might be surprised to see the result of the following code :-

1 //This time will not match your server time
2 $now = time();
3 echo date('m/d/y h:i:s', time());

This is because whatever settings you have in your php.ini, Magento reset timezone to ‘UTC’ in Mage_Core_Model_App.

File:- appcodecoreMageCoreModelApp.php Line:-255

1 date_default_timezone_set(Mage_Core_Model_Locale::DEFAULT_TIMEZONE);

So, solution is set your targeted timezone in Admin->System->Configuration / General->Locale options and rather using date() function user the following code:-

1 $now = Mage::getModel('core/date')->timestamp(time());
2 echo date('m/d/y h:i:s', $now);

That’s it, have happy time with Magento :-) .

类别 :  magento(258)  |  浏览(3987)  |  评论(0)
发表评论(评论将通过邮件发给作者):

Email: