Skip to content

Instantly share code, notes, and snippets.

@wjlafrance
Created March 5, 2016 06:10
Show Gist options
  • Save wjlafrance/87cde2d0800402fa3d17 to your computer and use it in GitHub Desktop.
Save wjlafrance/87cde2d0800402fa3d17 to your computer and use it in GitHub Desktop.
I don't know how to dateformatter
Expect: 2016-02-08 15:43:32 +0000
Got: 2016-02-08 18:43:32 +0000
2016-02-08 12:43:32 +0000
import Foundation
let formatter = NSDateFormatter()
formatter.dateFormat = "M/d/yyyy H:mm:ss a"
let date1 = formatter.dateFromString("2/8/2016 3:43:32 PM")!
formatter.timeZone = NSTimeZone(name: "GMT")!
let date2 = formatter.dateFromString("2/8/2016 3:43:32 PM")!
print("Expect: 2016-02-08 15:43:32 +0000")
print("Got: \(date1)")
print(" \(date2)")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment