1

I am trying to get the date from a JSON File and parse it in Swift.

the JSON File output is:

{"dateString":"2016-07-04T18:40:29+01:00"}

and I am getting it from the net using this:

 Alamofire.request(.GET, "http://www.timeapi.org/GMT/now.json")
        .responseJSON { response in
            switch response.result {
            case .Success:
                if let value = response.result.value {
                    let json = JSON(value)
                    for (_, value) in json {

                        let dateNow = value.stringValue


                        print("Date: \(dateNow)")



                    }
                }
            case .Failure(let error):
                print("This block called")
                print(error)


    }
    }

The output is:

2016-07-04T18:38:35+01:00

I need to be able to get the date and the time to store in separate variables.

I am really struggling, please can someone help :)

I tried :

var dateNow = NSDateFormatter()
dateNow = value

but then I get the error:

Cannot assign value of type 'JSON' to type 'NSDateFormatter'

JamesG
  • 1,552
  • 8
  • 39
  • 86
  • Tip: refer to http://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table to find your own string format. – Eric Aya Jul 04 '16 at 17:54

0 Answers0