Cesare
Cesare

Reputation: 9409

Parse yyyy:MM:dd:hh:mm:ss using DateFormatter in Swift

I would like to parse Year:Month:Day:Hour:Minute:Second (e.g. 2017:01:01:23:59:59) in Swift. I am using the following dateFormat: yyyy:MM:dd:hh:mm:ss though the date formatter returns nil when given a string:

let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy:MM:dd:hh:mm:ss"
dateFormatter.date(from: "2017:01:01:23:59:59") // nil

NSDateFormatter.com says there is something invalid in either my date or format. What am I doing wrong?

Upvotes: 0

Views: 854

Answers (1)

SIlvester
SIlvester

Reputation: 770

I believe your format is incorrect. It should be yyyy:MM:dd:HH:mm:ss instead. HH for hours.

Upvotes: 8

Related Questions