Magento gives wrong date and time

If I post the date / time in index.php echo date('m/d/Y h:i:s a', time()); . It is right. If I output the date / time anywhere after this, in the extension, for example, it should be exactly 4 hours. I set the time zone correctly in php.ini and in Magento, so I'm not sure what makes it shut down. I am running version 1.7.0.2.

EDIT

Good, so I learned a few things.

Magento always sets the time zone for UTC in app / mage.php

 line 767: date_default_timezone_set('UTC') 

So basically you cannot use date (), time (), etc. You should set your time zone in the Admin-> System-> Configuration / General-> Locale parameters and use something like:

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

I could always replace line 767 with my time zone, but I don't like modifying the kernel code. Are there any other options out there?

+6
source share
3 answers

The preferred method in Magento seems to use either date and time objects, or time values, rather than scalar values, as in this example . Once you have an object, you can easily convert it to other non-server time zones using setTimezone .

 // a more complete example $datetime = Zend_Date::now(); // admin controls this output through configuration $datetime->setLocale(Mage::getStoreConfig( Mage_Core_Model_Locale::XML_PATH_DEFAULT_LOCALE)) ->setTimezone(Mage::getStoreConfig( Mage_Core_Model_Locale::XML_PATH_DEFAULT_TIMEZONE)); echo $datetime->get(Zend_Date::DATETIME_SHORT); 
+7
source

If you save dates in the Magento database, make sure they are in UTC. By default, Magento saves all dates in UTC, but it should display them in the local time zone.

+4
source

In my case, the time changes, for example. system.log, but also in Scheduler (cronjobs).

So, let's say now it’s 01.15 in real time, the creation time in the scheduler is always correct, therefore in this case 01.15. What executes execution time 01.16, but often 02.16, so you see a combination of 01.16 and 02.16, so the time changes continuously.

When I check the system log, I see the same thing, first you see an increase in time for messages like 01.50, 02.45, 03.50 and again 02.55.

So, there is something in the system that allows you to vary this time, but where, maybe my provider will find something ... but this is not a system time, it is associated with Magento .. Magento writes to the journal.

EDIT:

Why I have this problem, I don’t know, but I changed the UTC time in Mage.php in my Europe / Amsterdam zone. Now all times are correct, also in magazines.

But one problem again, when I schedule a cronjob right away in the Scheduler (extension), this task is scheduled after 1 hour (the others in the scheduler are correct). The Copernica extension works, for example, at 6 p.m. (not through the Scheduler), and writes that it was completed the last time at 5 p.m. ... no other websites without Magento have such problems .. the database also uses Europe / Amsterdam in php.ini ..

0
source

Source: https://habr.com/ru/post/926601/


All Articles