Skip to content

Instantly share code, notes, and snippets.

@dleonard00
Created May 15, 2015 16:16
Show Gist options
  • Save dleonard00/d92661a17cf26c31c978 to your computer and use it in GitHub Desktop.
Save dleonard00/d92661a17cf26c31c978 to your computer and use it in GitHub Desktop.
RFC 3339 date string in Swift
var now = NSDate()
var localTimeZone = NSTimeZone.systemTimeZone()
var rfc3339DateFormatter = NSDateFormatter(format: "yyyy'-'MM'-'dd'T'HH':'mm':'ssZ")
rfc3339DateFormatter.locale = NSLocale( localeIdentifier: "en_US_POSIX")
rfc3339DateFormatter.timeZone = localTimeZone
var dateString = rfc3339DateFormatter.stringFromDate(now)
NSLog("RFC 3339 datetime: \(dateString)")
//reference: https://gist.github.com/popthestack/5877965