I am working on a time app which display time of different time zones. For this i am using a standard time haDate
(UTC tz).
For displayDate
i am using system time zone api. Time Zone is America/Santiago
(UTC-3:00).
NSTimeZone *tz=[NSTimeZone timeZoneWithName:_timeZone];
_displayDate=[_haDate dateByAddingTimeInterval:tz.secondsFromGMT];
"haDate" code -
NSDateFormatter *formatter=[[NSDateFormatter alloc]init];
formatter.timeZone=[NSTimeZone timeZoneWithName:@"UTC"];
NSString *utcTimeCurrent=[dict objectForKey:@"utctime"];
[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
_haDate=[formatter dateFromString:utcTimeCurrent];
The issue is when i run this code on simulator tz.secondsFromGMT
returns -10800
but on device it returns -14400
, which is 1 hour less.
Device and Simulator using same timeZone Asia/Kolkata
(UTC+5:30). I know America/Santiago
uses DST but why it is giving me different seconds even both (simulator and device) are on same timeZone.
What is wrong and how can i fix it?
NOTE
To fix DST issue i am using this code. But it always go to the else part on both devices. (BTW below code is not required because tz.secondsFromGMT
always return seconds after DST adjustments.)
NSTimeZone *tz=[NSTimeZone timeZoneWithName:_timeZone];
if (tz.isDaylightSavingTime)
{
_displayDate=[_haDate dateByAddingTimeInterval:tz.secondsFromGMT+tz.daylightSavingTimeOffset];
}
else
{
_displayDate=[_haDate dateByAddingTimeInterval:tz.secondsFromGMT];
}
When i log the tz -
On Simulator
tz America/Santiago (GMT-3) offset -10800
On Device
tz America/Santiago (GMT-4) offset -14400
So it is not using DST.
NOTE 2
This problem only occurs in iPad 2. Other devices working fine.
NOTE 3
My iPad 2 using iOS 8.4 . Both time zones (Chile Standard Time -America/Santiago
and Easter Island Standard Time - Pacific/Easter
) are giving me wrong seconds
America/Santiago
. It stored in a database.