Convert GMT NSDate to device's current Time Zone

前端 未结 6 1439
小蘑菇
小蘑菇 2020-12-08 05:30

I\'m using Parse.com to store some values:

\"enter

These are GMT values. How d

6条回答
  •  心在旅途
    2020-12-08 06:26

    This is a very clean way to change the NSDate to a local time zone date

    extension NSDate {
    
        func toLocalTime() -> NSDate {
    
            let timeZone = NSTimeZone.local
    
            let seconds : TimeInterval = Double(timeZone.secondsFromGMT(for:self as Date))
    
            let localDate = NSDate(timeInterval: seconds, since: self as Date)
            return localDate
        }
    }
    

    taken from https://agilewarrior.wordpress.com/2012/06/27/how-to-convert-nsdate-to-different-time-zones/

提交回复
热议问题