-4

I was trying to convert JSON date in to date time. But it's not working properly.

My Time Zone (.current) - > +05.30

Json date (string) -> 2017-06-23T04:30:43Z
The DateObject I Needed in the end -> 2017-06-23T10:00:43+0530

What I want in Convert json date in to a DateObject. I could not find any solution over internet thats why I'm asking.

Thank you.

gamal
  • 1,587
  • 2
  • 21
  • 43
  • try using `formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZ"` https://stackoverflow.com/questions/28016578/swift-how-to-create-a-date-time-stamp-and-format-as-iso-8601-rfc-3339-utc-tim/28016692#28016692 – Leo Dabus Jun 23 '17 at 05:46

1 Answers1

1

Use ISO8601DateFormatter (iOS 10.0+, macOS 10.12+)

let string = "2017-06-23T04:30:43Z"
let dateFormatter = ISO8601DateFormatter()
dateFormatter.date(from: string)

The operating system handles the time zone for you (except in print statements)

vadian
  • 274,689
  • 30
  • 353
  • 361