Skip to content

Instantly share code, notes, and snippets.

@naoty
Created December 9, 2016 06:03
Show Gist options
  • Save naoty/ba7ced344e55056ef2089855b40feb10 to your computer and use it in GitHub Desktop.
Save naoty/ba7ced344e55056ef2089855b40feb10 to your computer and use it in GitHub Desktop.
import Foundation
let utcFormatter = DateFormatter()
utcFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZZ"
utcFormatter.locale = Locale(identifier: "en_US_POSIX")
utcFormatter.timeZone = TimeZone(abbreviation: "UTC")
let jstFormatter = DateFormatter()
jstFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZZ"
utcFormatter.locale = Locale(identifier: "en_US_POSIX")
jstFormatter.timeZone = TimeZone(abbreviation: "JST")
let utcString = "2017-01-01T00:00:00+0000"
let jstString = "2017-01-01T00:00:00+0900"
utcFormatter.string(from: utcFormatter.date(from: utcString)!) // "2017-01-01T00:00:00Z"
utcFormatter.string(from: utcFormatter.date(from: jstString)!) // "2016-12-31T15:00:00Z"
jstFormatter.string(from: jstFormatter.date(from: utcString)!) // "2017-01-01T09:00:00+09:00"
jstFormatter.string(from: jstFormatter.date(from: jstString)!) // "2017-01-01T00:00:00+09:00"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment