Skip to content

Instantly share code, notes, and snippets.

@vietstone-ng
Created April 5, 2018 07:03
Show Gist options
  • Save vietstone-ng/aece06109d5834d53c4c14dceccec681 to your computer and use it in GitHub Desktop.
Save vietstone-ng/aece06109d5834d53c4c14dceccec681 to your computer and use it in GitHub Desktop.
Manage datetime with timezone
import SwiftDate
let response = "2018-04-25T06:00:00"
let format = "yyyy-MM-dd'T'HH:mm:ss"
let utc = Region.GMT()
let timeInUTC = response.date(format: .custom(format), fromRegion: utc)
print(timeInUTC)
let absoluteTime = timeInUTC?.absoluteDate
print(absoluteTime)
let timeInVietnam = DateInRegion(absoluteDate: absoluteTime!, in: Region.Local())
print(timeInVietnam.description)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment