Magento2: Magento 2 Timezone Issue

Created on 25 Nov 2016  Â·  37Comments  Â·  Source: magento/magento2


Preconditions


  1. Go to Admin -> Stores -> Configuration -> General -> Locale Options.
    Timezone set to "Singapore Standard Time (Asia/Singapore)"

On magento2\app\bootstrap.php at end of file there is static line written date_default_timezone_set('UTC');

If i need Magento Date

$magentoDateObject = $objectManager->create('Magento\Framework\Stdlib\DateTime\DateTime');
$magentoDate = $magentoDateObject->gmtDate();

I have to go to the file & change

Steps to reproduce

  1. Line should be removed from magento2\app\bootstrap.php date_default_timezone_set('UTC');

Expected result

  1. So will get Acutal Date

Actual result

  1. [Screenshot, logs]

Format is valid Ready for Work bug report

Most helpful comment

@magento-admin & @magento-team Any updates?

All 37 comments

@shahankitb997 thank you for your report.
Please specify Magento version you are running

Magento 2 CE Version 2.1.2

@veloraven This bug also affects newsletter queue. See issue #5943.

@Ctucker9233 You are correct. I'm not able to send newsletter as per set on Admin Locale.
http://magento.stackexchange.com/questions/147752/magento-2-newsletter-queue-take-different-queue-start-time

Don't know why they have put Static code for setting TimeZone? It's pointless to provide Admin Settings for Locale Timezone. If you are going to override it.

There should be only one way to set Timezone from Admin. No need the code of overriding it.

@shahankitb997 @veloraven When I dug around in MagentoFrameworkStdlibDateTimeDateTime, I noticed that there is supposed to be an offset created so that everything in the backend will display the proper local time. This offset seems to be broken or not used for some things. I believe it would fix the problem if that offset was also used in the newsletter queue.

@Ctucker9233 So what will be the solution or quick fix for this one?

@shahankitb997 I wish I had an answer for you. I haven't had time really to play with it. I have read in other issues of this type that changing the 'UTC' in date_default_timezone_set('UTC'); to your specific timezone code will temporarily fix the issue. But this modifies core code and would be overwritten in the case of an update or upgrade. @veloraven please give us some feedback and let us know that this issue is being taken seriously and what its priority level is. Ideally it's a one or two line fix so that the newsletter module inherits the correct timezone offset. Please advise.

Hi @Ctucker9233 & @veloraven Any updates on this?

@shahankitb997 I've got nothing. I'm actually not affiliated with Magento so I have no way of knowing.

Thanks. @Ctucker9233 for reply.

HI @veloraven any updates?

Does anyone have update on this one?

Thanks

Any updates?

@shahankitb997 I'm not sure that @veloraven is a real person. He/she never responds.

Hi @Ctucker9233 so who is concern i need to report to?

I've used @magento-admin and @magento-team with some success. In fact, if whoever is monitoring these tags reads this, we would appreciate a response.

@magento-admin & @magento-team Any updates?

Are more people having this issue? I have the exact same issue on Magento 2.1.3. The server, php and mysql time are set to Amsterdam. In the backend the locale is set to Amsterdam. However the time difference is 9 hours.

@J96 Yes, still have this problem. I'm on version 2.1.4. I believe it is messing with my cron jobs as well. They "look" like they run ok, but I am unable to do basic things like send newsletters and automatic re-indexing. I have to run these jobs manually in CLI and only then does it actually work.

@magento-team @magento-admin @magento-devops A little attention on this issue please!

I am experiencing similar problem here, using locale timezone for Brazil. Running Magento CE ver. 2.1.6.

For me the impact is when I want to know if the user has logged out.

I am getting this output:

Date time now: 24-04-2017 18:44:55
Last Login time: 2017-04-24 18:36:39
Last Logout time:

Last Visit time: 2017-04-24 18:36:43

When running getCurrentStatus() at MagentoBackendBlockTemplatePersonalInfo

The real date time at the moment of test was 04/24/2017 15:44:55

We already have internal ticket for this issue: MAGETWO-56349

@shahankitb997, thank you for your report.
The issue is already fixed in 2.2.0

@magento-engcom-team Please backport to 2.1 or mark as up for grabs.

I am not sure what you mean by back port to 2.1 or mark as up for grabs?

Can you provide documentation to do this.

thanks
Jason

On October 30, 2017 at 6:57:36 PM, Ctucker9233 ([email protected])
wrote:

@magento-engcom-team https://github.com/magento-engcom-team Please
backport to 2.1 or mark as up for grabs.

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/magento/magento2/issues/7560#issuecomment-340609615,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AfpkLDbZOga5L8w2AH1R072SYnGKErIcks5sxlRfgaJpZM4K8C-v
.

I have searched and I can not find how to do a backport or how to “Mark up
for grabs”.

I did find this ticket https://github.com/magento/magento2/issues/8470

Which may be a similar issue. I see that it was updated with a fix. Will
that fix my issue?

Please provide some direction. We a couple days from launching the site
and this is a huge set back.

Thanks
Jason

Jason Smith
CEO
Spot Marketing Group
p: 519.303.1154 Ext. 110 m: 226.268.0064
f: 519.303.1153
a: 132 Thames St. N. Ingersoll, ON N5C 2T4
w: www.spotmarketing.ca e: [email protected]
https://www.facebook.com/SpotMarketingG/
https://twitter.com/spotmarketingg
https://ca.linkedin.com/in/jason-smith-99240a63
[image: Inbound Certification] [image: HubSpot Certification] [image:
Inbound Sales Certification] [image: Partner Certification]
http://hubs.ly/H035cNn0

http://offers.spotmarketing.ca/art-of-social-selling

On October 30, 2017 at 6:58:48 PM, Jason Smith ([email protected])
wrote:

I am not sure what you mean by back port to 2.1 or mark as up for grabs?

Can you provide documentation to do this.

thanks
Jason

On October 30, 2017 at 6:57:36 PM, Ctucker9233 ([email protected])
wrote:

@magento-engcom-team https://github.com/magento-engcom-team Please
backport to 2.1 or mark as up for grabs.

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/magento/magento2/issues/7560#issuecomment-340609615,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AfpkLDbZOga5L8w2AH1R072SYnGKErIcks5sxlRfgaJpZM4K8C-v
.

@spotmarketing I was asking the Magento team to backport it or mark it up for grabs. Since the original issue was reported against 2.1 it should be fixed in 2.1 in my opinion. Unless you are part of the Magento team, this isn't likely something you can do.

Thanks but I am looking for an answer on this. It is not fixed in 2.1 and
we are unable to launch the site because of this issue.

How to I go about getting a resolution on this?

Thanks
Jason

Jason Smith
CEO
Spot Marketing Group
p: 519.303.1154 Ext. 110 m: 226.268.0064
f: 519.303.1153
a: 132 Thames St. N. Ingersoll, ON N5C 2T4
w: www.spotmarketing.ca e: [email protected]
https://www.facebook.com/SpotMarketingG/
https://twitter.com/spotmarketingg
https://ca.linkedin.com/in/jason-smith-99240a63
[image: Inbound Certification] [image: HubSpot Certification] [image:
Inbound Sales Certification] [image: Partner Certification]
http://hubs.ly/H035cNn0

http://offers.spotmarketing.ca/art-of-social-selling

On December 14, 2017 at 4:58:38 PM, Ctucker9233 ([email protected])
wrote:

@spotmarketing https://github.com/spotmarketing I was asking the Magento
team to backport it or mark it up for grabs. Since the original issue was
reported against 2.1 it should be fixed in 2.1 in my opinion. Unless you
are part of the Magento team, this isn't likely something you can do.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/magento/magento2/issues/7560#issuecomment-351848545,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AfpkLItR0zbcyWy8Qjwkn9pnNKtVXuG5ks5tAZoNgaJpZM4K8C-v
.

@spotmarketing You would have to look at the commits listed in this issue thread and cherry pick it into your magento version. That's the only way I would know how to resolve it right now. I just hope @magento-engcom-team is listening and will backport this to a 2.1 version sometime soon.

Hi Guys!
Please don't remove date_default_timezone_set('UTC'); from the bootstrap file. This would not fix your data inconstancy, but let Magento shows data in "right" way.

Basically, Magento 2 uses CURRENT_TIMESTAMP as the default value for most of data fields (like created_at/updated_at). To check what is your current timestamp, you can execute the following SQL query:

SELECT CURRENT_TIMESTAMP;

As a result, we would see date in the default server timezone. However, Magento 2 expects to see it in UTC and that's good if your server/database timezone in UTC, but if it's not, you would get this issue.

So please make sure that system stores data in UTC in your database. If not, please make it so, and then Magento 2 would work with dates as expected.

The downside is 3rd-party that are not locale into account, but this is kind of different story.

Hopefully you find this experience helpful :)

For anybody who is having a timezone construct admin error on their magento 2.3.0 admin once logging in post upgrade from Magento 2.2.6 (similar to this)

Http error
magento Stdlib/DateTime/Timezone.php(199): DateTimeZone->__construct('')

Magento_log
[2018-12-11 16:42:46] main.ERROR: DateTimeZone::__construct(): Unknown or bad timezone () [] []

The easiest workaround is to check that your admin_users table are all using the interface local of your default store. My users where set to use en_US when actually my stores timezone and language where all set to en_GB

Once manually updating the database records for each user re-run bin/magento setup:upgrade

Hi All,

I am using Magento 2.3.0 and still facing issue regarding Order Date after migration from Magento 1. Can any body suggest me a working solution for this issue.

+1 on having this issue still on Order Date from Mage 1 to Mage 2 (2.2.6)

bootstrap.php shows UTC

config > locale options set to "America/Chicago" and last order should be 3pm and it's showing 1am.

Server Time is correct (Europe/Amsterdam), PHP is correct (Europe/Amsterdam).
Magento2 is set to Europe/Amsterdam.
However Time is always off with one hour.
It's now 22:29 but magento will tell me it's 21:29.
This is on 8 M2 installations with PHP 7.2 and Magento 2.3

Why is this issue closed, yet people are still experiencing the issue??

Hi,

Do anyone have any solution for the issue so far...? i upgraded to Magento 2.3.1 but issue is still there.

@netzwelt-nishu - are you using different timezones for admin users i.e en_US en_GB? - If so as a work-around try and set all your admin users to use the same timezone as your default store

Someone found a solution?
Magento 2.2.6

Was this page helpful?
0 / 5 - 0 ratings