0

I have a wordpress website hosted at Hostgator (Brazil). The server shows the current correct time (in daylight saving time). In this example, the correct time is as below, ie 13h (America / São Paulo). Logging in via putty.exe:

user@site.com.br [~] # date

Sun Nov 11 13:55:01 -02 2018 << - correct time / daylight saving time America / São Paulo

However, inside a PHP script, I get the time in 2 hours:

echo date ("e / d-m-Y G: i: s");

UTC / 11-11-2018 15:55:01

At the same time, within Wordpress (Admin -> Settings -> General), the "Time Zone" field is set to UTC-3 where it shows:

Universal time (UTC) is 11/11/2018 15:55:01. Local time is 11/11/2018 12:55:01.

In short, the server shows 13h (correct in current time in São Paulo DST), but PHP shows15h and Wordpress shows 12h.

How to regularize this, that is, that the 3 cases have the same time?

  • Note that not all of those are times, some of them are timestamps, nor should they all match – Tom J Nowell Nov 11 '18 at 23:55
2

In short, the server shows 13h (correct in current time in São Paulo DST), but PHP shows15h and WordPress shows 12h.

This is intentional, and needs additional clarification, but to expand you have:

  • The server local time
  • UTC timestamps
  • Localised WP time

These needs to be separate, e.g. if I host a Japanese website on a server in Moscow:

  • The server local time would be that of Moscow
  • UTC Timestamps are timestamps, they're always UTC
  • Local WP time would be UTC timestamp + offset, aka whatever offset Tokyo time is.

It would seem that your local WP install is configured with the wrong timezone

How to regularize this, that is, that the 3 cases have the same time?

You don't, your mental model of how it works is incorrect.

WordPress stores all times in UTC as timestamps. Timestamps are not localized, 12pm UTC for me, is 12pm UTC for you no matter which timezone you are in. WordPress then adds or subtracts an offset based on the desired display timezone.

It's that offset that you need to change, and that's what the timezone setting does, which is exactly what the description on the setting says:

enter image description here

Clearly whatever value your site has in that drop down was chosen incorrectly, perhaps daylight savings was not taken into account ( e.g. if you're in a UTC+4 timezone, and daylight savings jumps forward an hour, you are no longer UTC+4, you're in UTC+5 )

As for server time, if you're in PHP you'll have to convert it to UTC first, or request it in UTC. It might also work to format the server time as a timestamp making sure to include the timezone/offset, but this will only work with newer PHP datetime APIs

You may also find this useful in understanding the difference between a time and a timestamp with regards to timezones

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.