Skip to content

Instantly share code, notes, and snippets.

@ryan-blunden
Created May 1, 2016 23:09
Show Gist options
  • Save ryan-blunden/c6aafa054e158f6201ffe7723d314537 to your computer and use it in GitHub Desktop.
Save ryan-blunden/c6aafa054e158f6201ffe7723d314537 to your computer and use it in GitHub Desktop.
struct DateUtils {
static let isoDateFormatter: NSDateFormatter = NSDateFormatter()
static func toISO8601(date: NSDate) -> String {
isoDateFormatter.locale = NSLocale(localeIdentifier: "en_US_POSIX") // Why en_US_POSIX? - https://developer.apple.com/library/mac/qa/qa1480/
isoDateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZZ" // ISO8601 format
return isoDateFormatter.stringFromDate(date)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment