简体   繁体   English

使用Objective-C / C查找DST(夏令时)时间戳?

[英]Find DST (Daylight Savings Time) timestamp using Objective-C/C?

Is there a way to get the specific date (way) when daylight davings begins and ends for each country using C or Objective-C? 有没有办法在使用C或Objective-C的每个国家的日光开始和结束时获得具体日期(方式)?

In the Mexico, summer time begins on the first Sunday in April at 2:00am, and ends on the last Sunday in October at 2:00am. 在墨西哥,夏季时间从4月的第一个星期日凌晨2:00开始,到10月的最后一个星期日凌晨2:00结束。 In many POSIX systems this is written as 在许多POSIX系统中,这被写成

M4.1.0/2,M10.5.0/2
(Begins: Month 4, 1st Sunday at 02:00AM, Ends: Month 10, last Sunday at 02:00AM)

I know it is possible to know if daylight savings is currently active using 我知道有可能知​​道当前是否正在使用夏令时

NSTimeZone* systemTimeZone = [NSTimeZone systemTimeZone];
BOOL dstIsOn = [systemTimeZone isDaylightSavingTime];

and that it is possible to get the time until the next Daylight Savings begins 并且可以获得直到下一个Daylight Savings开始的时间

NSTimeZone* systemTimeZone = [NSTimeZone systemTimeZone];
NSTimeInterval delta = [systemTimeZone daylightSavingTimeOffset];

BUT: How would I go about finding the specific day that the daylight savings begins/ends? 但是:我如何才能找到夏令时开始/结束的具体日期?

Is there some killer table out there that I have not been able to find? 那里有一些我无法找到的杀手表吗?

Any help would be greatly appreciated! 任何帮助将不胜感激!

Yes, there is - you can use [NSTimeZone nextDaylightSavingTimeTransitionAfterDate:] method. 是的,有 - 你可以使用[NSTimeZone nextDaylightSavingTimeTransitionAfterDate:]方法。 This returns an NSDate , which you can use with daylightSavingTimeOffsetForDate to establish what the offset is. 这将返回一个NSDate ,您可以将其与daylightSavingTimeOffsetForDate一起使用以确定偏移量。

Normally you'd use this to find the next offset, but you can obviously run it more than once with different dates to get a series of upcoming daylight saving changes. 通常你会用它来查找下一个偏移量,但是你可以用不同的日期多次运行它来获得一系列即将到来的夏令时变化。 There is also a convenience method nextDaylightSavingTimeTransition which will always return the next transition. 还有一个方便的方法nextDaylightSavingTimeTransition ,它将始终返回下一个转换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM