Here’s a NSDate category to convert UTC (or GMT) to local time and back.
#import "NSDate+Utils.h" @implementation NSDate (Utils) -(NSDate *) toLocalTime { NSTimeZone *tz = [NSTimeZone localTimeZone]; NSInteger seconds = [tz secondsFromGMTForDate: self]; return [NSDate dateWithTimeInterval: seconds sinceDate: self]; } -(NSDate *) toGlobalTime { NSTimeZone *tz = [NSTimeZone localTimeZone]; NSInteger seconds = -[tz secondsFromGMTForDate: self]; return [NSDate dateWithTimeInterval: seconds sinceDate: self]; } @end
Links that help
http://stackoverflow.com/questions/1268509/convert-utc-nsdate-to-local-timezone-objective-c
http://stackoverflow.com/questions/5985468/iphone-differences-among-time-zone-convenience-methods
Convert UTC NSDate to local Timezone Objective-C | ASK AND ANSWER
Jan 17, 2016 @ 20:35:16
seanperez29
Jun 04, 2017 @ 17:20:09
This extension is awesome! Looked all over on how to convert UTC to local time, your solution is best I’ve seen. Thanks!
Convert UTC NSDate to local Timezone Objective-C - ExceptionsHub
Dec 08, 2017 @ 07:07:59
Chuck Gusti Noris
Aug 16, 2019 @ 08:49:03
Great job!!! NSDate category is just the best and most elegant solution.
Thanks for sharing. You rescued me with that issue.
iOS: Convert UTC NSDate to local Timezone - iZZiSwift
Oct 06, 2020 @ 03:26:47
iOS:将UTC NSDate转换为本地时区|ios问答
Nov 11, 2020 @ 04:12:44
[ios] iOS : UTC NSDate를 현지 시간대로 변환 - 리뷰나라
Aug 20, 2021 @ 20:01:41