admin管理员组文章数量:1130349
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:
[email protected] [~] # 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?
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:
[email protected] [~] # 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?
Share Improve this question asked Nov 11, 2018 at 19:49 Rogério DecRogério Dec 1993 silver badges12 bronze badges 1- Note that not all of those are times, some of them are timestamps, nor should they all match – Tom J Nowell ♦ Commented Nov 11, 2018 at 23:55
1 Answer
Reset to default 2In 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:
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
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:
[email protected] [~] # 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?
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:
[email protected] [~] # 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?
Share Improve this question asked Nov 11, 2018 at 19:49 Rogério DecRogério Dec 1993 silver badges12 bronze badges 1- Note that not all of those are times, some of them are timestamps, nor should they all match – Tom J Nowell ♦ Commented Nov 11, 2018 at 23:55
1 Answer
Reset to default 2In 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:
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
本文标签: php3 different times on my Wordpress website
版权声明:本文标题:php - 3 different times on my Wordpress website 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749189672a2329976.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论