How to get current NSDate for Date simulator? iPhone Sdk

I am trying to get the current date with the addition of the time zone of the device, but will show 1 hour later than this starting date. I have a problem with DaylightSavingTime. How to disable isDaylightSavingTime = FALSE.

here is the code i used ..

NSDate *date = [NSDate Date]; NSTimeZone *currentTimeZon = [NSTimeZone localTimeZone]; if ([currentTimeZon isDaylightSavingTime]) { NSLog(@"East coast is NOT on DT"); } else { NSLog(@"East coast is on DT"); } NSTimeInterval timeZoneOffset = [currentTimeZon secondsFromGMTForDate:currentDate]; NSTimeInterval gmtTimeInterval = [date timeIntervalSinceReferenceDate] - timeZoneOffset; NSDate *gmtDate = [NSDate dateWithTimeIntervalSinceReferenceDate:gmtTimeInterval]; NSLog(@"### Announcement gmtDate = %@",gmtDate); 

I get a time difference of 1 hour, the date is performative.

+6
source share
1 answer

Use NSCalendar, it understands time zones, daylight saving, etc. As @albertamg writes, NSDate is only the time since the link in UTC (GMT), it has no other concept.

+1
source

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


All Articles