2014/03/30 02:00 - > 02:59
I am parsing a CSV to train a basic neural net. Every row corresponds to one minute. The code has no trouble parsing the rest of 2014 but that one hour results in a nil value. There is no difference in notation.
I also tried in a playground. Same problem. Just paste the code below in a playground and change the hour or the day.
var dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "yyyy/MM/dd HH:mm"
let dateString : String = "2014/03/30 02:53"
if dateFormatter.dateFromString(dateString) == nil {
print("bad date \(dateString)")
} else {
let date : NSDate = dateFormatter.dateFromString(dateString)!
let newDateString = dateFormatter.stringFromDate(date)
}
2014/03/30 02:55,1017,0,1.917,70.8,5.074,99,0,13.84
2014/03/30 02:56,1017,0,2.146,65.26,5.036,99,0,13.84
2014/03/30 02:57,1017,0,1.313,71.2,5.033,99,0,13.84
2014/03/30 02:58,1017,0,1.292,74.9,5.047,99,0,13.84
2014/03/30 02:59,1017,0,2.125,68.76,5.039,99,0,13.83
2014/03/30 03:00,1017,0,1.438,61.02,5.011,99,0,13.84
2014/03/30 03:01,1017,0,2.333,66.73,4.981,99,0,13.84
Working Code:
UTC timezone has no Daylight Savings
var dateFormatter = NSDateFormatter()
dateFormatter.timeZone = NSTimeZone(abbreviation: "UTC")
dateFormatter.dateFormat = "yyyy/MM/dd HH:mm"
let dateString : String = "2014/03/30 02:53"
if dateFormatter.dateFromString(dateString) == nil {
print("bad date \(dateString)")
} else {
let date : NSDate = dateFormatter.dateFromString(dateString)!
let newDateString = dateFormatter.stringFromDate(date)
}