Skip to content

Instantly share code, notes, and snippets.

@rydermackay
Last active October 6, 2016 01:54
Show Gist options
  • Save rydermackay/0396ea918ce420af842aa1474efbbc93 to your computer and use it in GitHub Desktop.
Save rydermackay/0396ea918ce420af842aa1474efbbc93 to your computer and use it in GitHub Desktop.
import Cocoa
private let _rfc3339Formatter: DateFormatter = {
let formatter = DateFormatter()
formatter.dateFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'"
formatter.timeZone = TimeZone(secondsFromGMT: 0)
formatter.locale = Locale(identifier: "en_US_POSIX")
return formatter
}()
extension DateFormatter {
static var rfc3339Formatter: DateFormatter {
return _rfc3339Formatter
}
}
let dateString = "2002-10-02T15:00:00Z"
DateFormatter.rfc3339Formatter.date(from: dateString) // "Oct 2, 2002, 11:00 AM"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment