最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

WordPress detects the wrong timezone

programmeradmin1浏览0评论

Both my server local time and timezone are correct (UTC -3).

$ date -u
Fri May 17 23:53:01 UTC 2019

$ date -Is
2019-05-17T20:53:10-03:00

$ ls -l /etc/localtime
lrwxrwxrwx 1 root root 37 May 17 20:41 /etc/localtime -> /usr/share/zoneinfo/America/Sao_Paulo

$ cat /etc/timezone 
America/Sao_Paulo

However, WordPress thinks my server is on UTC timezone and dials back 3 hours.

Timezone

Choose either a city in the same timezone as you or a UTC timezone offset.

Universal time (UTC) is 2019-05-17 19:38:06. Local time is 2019-05-17 16:38:06.

This timezone is currently in standard time. Daylight saving time begins on: November 2, 2019 11:00 pm.

How do I fix this?

Both my server local time and timezone are correct (UTC -3).

$ date -u
Fri May 17 23:53:01 UTC 2019

$ date -Is
2019-05-17T20:53:10-03:00

$ ls -l /etc/localtime
lrwxrwxrwx 1 root root 37 May 17 20:41 /etc/localtime -> /usr/share/zoneinfo/America/Sao_Paulo

$ cat /etc/timezone 
America/Sao_Paulo

However, WordPress thinks my server is on UTC timezone and dials back 3 hours.

Timezone

Choose either a city in the same timezone as you or a UTC timezone offset.

Universal time (UTC) is 2019-05-17 19:38:06. Local time is 2019-05-17 16:38:06.

This timezone is currently in standard time. Daylight saving time begins on: November 2, 2019 11:00 pm.

How do I fix this?

Share Improve this question edited May 17, 2019 at 23:53 That Brazilian Guy asked May 17, 2019 at 22:43 That Brazilian GuyThat Brazilian Guy 1,2413 gold badges19 silver badges43 bronze badges 3
  • Possibly related: wordpress.stackexchange/questions/301392/… – That Brazilian Guy Commented May 17, 2019 at 22:54
  • Is the local time correct though? Keep in mind it will always tell you the time in UTC, there's a difference between a timestamp and a time/date. timestamps are always in UTC, you choose an offset and everything is offset on the fly. If your server is setting UTC time to your local time then that will cause major problems – Tom J Nowell Commented May 17, 2019 at 23:06
  • @TomJNowell I'm not sure if I follow. Who's this "it" that will always show the time in UTC? WordPress? PHP? The server itself? Doesn't date -Is guarantee that I'm getting the local time? Doesn't the T20:53:10-03:00 part indicates that? Am I mistaken here? Or do you mean something else? – That Brazilian Guy Commented May 17, 2019 at 23:55
Add a comment  | 

1 Answer 1

Reset to default 0

Turns out there was a previous attempt to fix the timezone:

date_default_timezone_set('America/Sao_Paulo');

was called on the init hook.

When later the correct UTC time, local time and timezone were properly set on the server, this caused a conflict.

Removing this solved the issue.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论