PHP日期(“I”)用于未来或过去日期 [英] PHP date("I") for a future or past date

查看:177
本文介绍了PHP日期(“I”)用于未来或过去日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PHP date(I)返回0或1,具体取决于当前日期是否为夏令时。但是,我需要这个确切的功能,在将来或过去的指定日期和时间返回0或1。

The PHP date("I") returns either a 0 or 1 depending on if the current date is in daylight savings. However, i need this exact function to return a 0 or 1 for a specified date and time in the future or past.

任何想法如何实现?

推荐答案

未来日期的时间戳如下:

Just pass the timestamp of the future date like this:

is_daylisght_saving = date("I", future_timestamp);

请参阅PHP date() 文档

See PHP date() documentation

**** *编辑:**

***** **

要正确获取夏令时信息,您需要确保将默认语言环境设置为使用夏令时的国家/地区。可以在这里找到使用夏令时的国家列表。

To properly get the daylight saving information you need to make sure that your default locale is set to a country using daylight saving. The list of countries using daylight savings can be found here.

要更改默认时区,请使用 date_default_timezone() 如下:

To change the default time zone use date_default_timezone() as follows:

date_default_timezone_set('Europe/Rome'); // Italy uses daylight saving
echo date("I", 1366456706); // will return 1

date_default_timezone_set('America/Argentina/Buenos_Aires'); // Argentina doesn't use daylight saving
echo date("I", 1366456706);  // will return 0

这篇关于PHP日期(“I”)用于未来或过去日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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