Skip to content

Instantly share code, notes, and snippets.

@micheltlutz
Created September 3, 2018 17:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save micheltlutz/5421a774be2b82fa8a005a9b4f0bc932 to your computer and use it in GitHub Desktop.
Save micheltlutz/5421a774be2b82fa8a005a9b4f0bc932 to your computer and use it in GitHub Desktop.
Create Date from TimeStemp String
func formatterDate(stringDate: String) -> Date? {
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSSxxxxx"
formatter.timeZone = Calendar.current.timeZone
formatter.locale = Calendar.current.locale
guard let newDate = formatter.date(from: stringDate) else { return nil }
return newDate
}
let stringDate = formatterDate(stringDate: "2018-08-30T15:26:27.357902-03:00")
print(stringDate)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment