B-219 Sec-55 Noida, India
+918010221733

Magento date time

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 :-

//This time will not match your server time
$now = time();
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


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:-


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

That’s it, have happy time with Magento 🙂 .

(Visited 64 times, 1 visits today)

Leave a reply

You must be logged in to post a comment.