IPhone: NSDate and DST

I use NSDate to measure program execution. I start the NSDate instance at startup, and then at the end I create a new endDate instance and call:

 [startDate timeIntervalSinceDate: endDate] 

This works fine, but I'm interested in what happens if the program starts execution before changing the DST and ends after. Will startDate start in the future and the timeInterval method will return a negative value?

+4
source share
3 answers

It would seem that what Darren meant is true. NSDate is a reference to the interval from the absolute key date, January 1, 2001, 00:00 GMT. Therefore, the class method [NSDate date] will return a representation of this interval. Thus, the future will not be considered a date.

0
source

I believe NSDates are absolute points in time and are not executed using daylight saving time or time zones. For example, now it’s exactly the same time in New York and Beijing, although due to time zones it can be 10 in the morning in New York and 10 in the evening in Beijing. A minute after switching from DST to ST, it will be a minute later, although earlier your watch could read 59 minutes earlier. Therefore, I think that if you create dates using [NSDate date], you will always get the correct time interval.

You can check it by setting the date of your device just before switching to (or off) the DST and registering the interval using the start date before the switch and the end date after the switch.

+2
source

This is not an iPhone only issue. I have a link that talks about this in terms of server and client time. The only workaround for this problem is to select the time zone for both the Maximo application server and the GUI client that does not use daylight saving time.

Link

Hope this clears your doubts.

0
source

Source: https://habr.com/ru/post/1434209/


All Articles