如何在PHP中使用is_dst参数获取正确的时间戳?

时间:2022-10-16 08:24:49

We are creating a unix timestamp with the mktime method giving following attributes:

我们使用mktime方法创建一个unix时间戳,给出以下属性:

print_r(mktime(0,0,0,3,1,2009));
print_r(mktime(null,null,null,3,1,2009) / 60 / 60 / 24) . "days");`

this creates a result of

这会产生一个结果

1235862000

14303.958333333 days

this should be 14304 days. The problem in this case is the winter hour. You can use the is_dst parameter, and when we use 0 (default -1) this sometimes works correctly giving 14304 days as a result.

这应该是14304天。在这种情况下的问题是冬季时间。你可以使用is_dst参数,当我们使用0(默认-1)时,这有时会正常工作,结果是14304天。

But sometimes this gives following problem:

但有时这会产生以下问题:

Strict Standards: mktime() [function.mktime]:The is_dst parameter is deprecated

严格标准:mktime()[function.mktime]:不推荐使用is_dst参数

i have no idea what it means and what i can do about it. Any idea someone? because the winter hour is causing terrible head ache....

我不知道这意味着什么,我能做些什么。有人在想吗?因为冬天的时候会引起可怕的头痛......

3 个解决方案

#1


Use gmmktime.

#2


date("I", time());

Will give you 1 if its daylight savings and 0 if its not.

如果它的夏令时会给你1,如果没有它会给你0。

#3


From the php manual page:

从php手册页:

"Every call to a date/time function will generate a E_NOTICE if the time zone is not valid, and/or a E_STRICT message if using the system settings or the TZ environment variable. See also date_default_timezone_set()"

“如果时区无效,则每次调用日期/时间函数都会生成E_NOTICE,如果使用系统设置或TZ环境变量,则会生成E_STRICT消息。另请参阅date_default_timezone_set()”

that probably means you should use date_default_timezone_set() previously and skip the is_dst parameter

这可能意味着您应该先使用date_default_timezone_set()并跳过is_dst参数

#1


Use gmmktime.

#2


date("I", time());

Will give you 1 if its daylight savings and 0 if its not.

如果它的夏令时会给你1,如果没有它会给你0。

#3


From the php manual page:

从php手册页:

"Every call to a date/time function will generate a E_NOTICE if the time zone is not valid, and/or a E_STRICT message if using the system settings or the TZ environment variable. See also date_default_timezone_set()"

“如果时区无效,则每次调用日期/时间函数都会生成E_NOTICE,如果使用系统设置或TZ环境变量,则会生成E_STRICT消息。另请参阅date_default_timezone_set()”

that probably means you should use date_default_timezone_set() previously and skip the is_dst parameter

这可能意味着您应该先使用date_default_timezone_set()并跳过is_dst参数