检查DST是否有效 [英] Check if DST is in effect

查看:111
本文介绍了检查DST是否有效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在PHP中,date('I')会告诉我夏令时是否有效.这是否告诉我DST是否仅针对服务器配置的时区有效,或者它是否处于有效期?

In PHP, date('I') will tell me if Daylight Savings Time is in effect. Does this tell me if DST is in effect specifically for my server's configured timezone, or whether or not it's in effect period?

我在亚利桑那州,我们不遵守夏令时.因此,我需要我的服务器识别出,例如,纽约现在比我快2个小时,但是明年DST在明年3月启动时,它比我快3个小时.

I'm in Arizona where we don't observe DST. So I need my server to recognize that, say, New York is 2 hours ahead of me right now, but when DST kicks in March next year that it's 3 hours ahead of me.

更新:

考虑到它是针对服务器配置的时区的注释,如果知道值在一年中不断变化,我将如何确定服务器的时区与任意时区之间的当前时差?

Given the comment that it's for my server's configured time zone, how would I go about determining the current time difference between my server's time zone and some arbitrary timezone, knowing that the value changes throughout the year?

推荐答案

PHP将遵守您服务器的默认时区,因此,如果您的服务器配置正确,date('I')在亚利桑那州将始终返回false.

PHP will honor your server's default time zone, so date('I') will always return false in Arizona if your server is correctly configured.

您可以将默认时区临时更改为遵守DST的区域.要更改默认时区,请使用 date_default_timezone_set()此处所示.

You may temporarily change the default time zone to an area that does observe DST. To change the default time zone use date_default_timezone_set() as indicated here.

这篇关于检查DST是否有效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆