Any way to get timezone abbreviation(e.g UTC, EET) from NSDate? I'm getting NSDate from string, e.g 2012-08-26 02:54:50 +0200 and need to show timezone of this date.
Currently doing that:
NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease];
[formatter setDateFormat: @"yyyy-MM-dd HH:mm:ssZZZ"];
NSDate *isoDate = [formatter dateFromString: isoTime.value];
NSInteger offset = [[NSTimeZone defaultTimeZone] secondsFromGMTForDate: isoDate];
NSTimeZone *timeZone = [NSTimeZone timeZoneForSecondsFromGMT: offset];
But I'm getting GMT+03:00 for timeZone abbreviation, but it should be EET. Any way to get it?
An NSDate
is time zone independent; it doesn't inherently have a time zone. You therefore can't get a time zone from it.
secondsFromGMTForDate:
returns the offset of that time zone (the default one, in your case) from GMT at the specified date. It's returning information about the NSTimeZone
which may depend on the date (eg, if your time zone honours daylight savings), not about the date.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With