This question already has an answer here:
I have this simple code:
let string = "2017-02-23 15:26:00";
let df = DateFormatter();
df.dateFormat = "yyyy-MM-dd hh:mm:ss";
let result = df.date(from: string);
The result is nil. Why?
This question already has an answer here:
I have this simple code:
let string = "2017-02-23 15:26:00";
let df = DateFormatter();
df.dateFormat = "yyyy-MM-dd hh:mm:ss";
let result = df.date(from: string);
The result is nil. Why?
Your date is 24 hour format So it should be
HH
nothh
, so change your date formate toyyyy-MM-dd HH:mm:ss
.