Created
May 19, 2016 06:00
-
-
Save apphands/70c01b8edb17e64bb516842eb4d25202 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
public extension NSDate { | |
public class func ISOStringFromDate(date: NSDate) -> String { | |
var dateFormatter = NSDateFormatter() | |
dateFormatter.locale = NSLocale(localeIdentifier: "en_US_POSIX") | |
dateFormatter.timeZone = NSTimeZone(abbreviation: "GMT") | |
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS" | |
return dateFormatter.stringFromDate(date).stringByAppendingString("Z") | |
} | |
public class func dateFromISOString(string: String) -> NSDate { | |
var dateFormatter = NSDateFormatter() | |
dateFormatter.locale = NSLocale(localeIdentifier: "en_US_POSIX") | |
dateFormatter.timeZone = NSTimeZone.localTimeZone() | |
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZ" | |
return dateFormatter.dateFromString(string) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment