如何在php中获取正确的时间

huangapple go评论91阅读模式
英文:

How do I get the correct time in php

问题

每次我使用下面的代码获取时间时,为什么会显示比正确时间提前1小时。我在其他编程语言(如JavaScript)中也遇到了相同的问题,每次想获取当前时间时,都会显示提前1小时?

每次我尝试在我的系统上获取不同时区的时间时,都会显示提前1小时,即使在世界协调时间(UTC)上,如果全球时间是12:00:00,它也会显示11:00:00,并且我在所有时区都遇到了相同的问题。
我测试了这段代码:

date_default_timezone_set('UTC');
echo date('H:i:s', time());
英文:

Why every time I get the time with the code below it shows 1 hour before the correct time. I have the same issue with other languages like javascript Every time i want to get the current time it shows 1 hour past?

every time I try to get time on my system on any timezones I get 1 hour last i.a in utc if the worldwide time is 12:00:00 it shows me 11:00:00 on utc and i have the same problem with all timezones.
I tested this code

date_default_timezone_set('UTC');
echo date('H:i:s', time());

答案1

得分: 2

伊朗政府于2022年9月22日废除了夏令时(DST)。因此,在该日期之前创建的任何软件都不会包括这一更改。显然,您的服务器/计算机仍然包含这样一个过时的软件并且仍然应用DTS。

在大多数情况下,简单更新操作系统即可纠正此问题。在Linux中,时区信息存储在一个小型数据库中。有关如何更新Linux的信息,请参阅:下载tz数据库

英文:

In Iran the government abolished daylight saving time (DST) on 22 September 2022.

Any software created before that date could therefore not have included this change. Clearly your server/computer contains such an outdated piece of software and still applies DTS.

In most case a simple update of the operating systems will rectify the problem. In Linux the time zones are stored in a small database. For how to update Linux see: Downloading the tz database.

huangapple
  • 本文由 发表于 2023年7月17日 21:21:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/76704902.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定