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'