So, I was looking another question over here, and cross upon this:
I have an extension for NSDate
extension NSDate {
private class var formatter : NSDateFormatter {
let nsDateFormatter = NSDateFormatter()
nsDateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss ZZZ"
nsDateFormatter.locale = NSLocale.currentLocale()
return nsDateFormatter
}
//NSString to NSDate
public convenience init(dateString:String) {
let dateObj = NSDate.formatter.dateFromString(dateString)!
self.init(timeInterval: 0, sinceDate: dateObj)
}
//NSDate to String
public func getString() -> String {
return NSDate.formatter.stringFromDate(self)
}
}
This works just fine:
var date = NSDate() //"Feb 2, 2016, 12:36 PM"
var string = date.getString() //"2016-02-02 12:36:11 -0500"
let copyDate = NSDate(dateString: string) //"Feb 2, 2016, 12:36 PM"
copyDate.getString() //"2016-02-02 12:36:11 -0500"
But if I use, for example:
"EEE, d MMM YYYY HH:mm:ss zzz" as the dateFormat:
var date = NSDate() //"Feb 2, 2016, 12:58 PM"
var string = date.getString() //"Tue, 2 Feb 2016 12:58:48 GMT-5"
let copyDate = NSDate(dateString: string) //"Dec 22, 2015, 12:58 PM"
copyDate.getString() //"Tue, 22 Dec 2015 12:58:48 GMT-5"
Why is this happening?
It shouldn't be working equal to the previous case?
Why I have now several days and even a month of time disruption?