How do I convert a UTC NSDate
to local timezone NSDate in Objective C or/and Swift?
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- Using if let syntax in switch statement
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- xcode 4 garbage collection removed?
- Unable to process app at this time due to a genera
- Enum with associated value conforming to CaseItera
EDIT When i wrote this I didn't know I should use a dateformatter which is probably a better approach, so check out
slf
's answer too.I have a webservice that returns dates in UTC. I use
toLocalTime
to convert it to local time andtoGlobalTime
to convert back if needed.This is where I got my answer from:
https://agilewarrior.wordpress.com/2012/06/27/how-to-convert-nsdate-to-different-time-zones/
The easiest method I've found is this:
You can try this one:
Convert UTC time to current time zone.
call function
Function
Convert the date from the UTC calendar to one with the appropriate local NSTimeZone.