How can I get the Timezone offset in Objective-C (for iPhone OS 3)?
For example, GMT -5
is US Eastern Time. I want the -5
part of it. How would I do so?
You can get the offset of a timezone using ZonedDateTime#getOffset . Note that the offset of a timezone that observes DST changes as per the changes in DST. For other places (e.g. India), it remains fixed. Therefore, it is recommended to mention the moment when the offset of a timezone is shown.
timeZone = [NSTimeZone timeZoneForSecondsFromGMT:0]; //Create a date string in the local timezone dateFormatter. timeZone = [NSTimeZone timeZoneForSecondsFromGMT:[NSTimeZone localTimeZone]. secondsFromGMT]; NSString *localDateString = [dateFormatter stringFromDate:[NSDate date]]; NSLog(@"date = %@", localDateString);
Purpose. The GMTOFFSET statement specifies the Greenwich Mean Time offset, which is the number of hours and minutes that the time differs from Greenwich Mean Time (also called Coordinated Universal Time, or UTC).
[[NSTimeZone localTimeZone] secondsFromGMT] / 3600
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