xcode swift am/pm time to 24 hour format -
i trying convert am/pm format time 24 hour format time
6:35 pm 18:35
i tried piece of code on playground doesnt seem work if put time alone
let dateasstring = "02/12/15, 6:35 pm" let dateformatter = nsdateformatter() dateformatter.dateformat = "hh" let date = dateformatter.datefromstring(dateasstring) //returns nil
does know how accomplish this?
thank you.
just convert date using nsdateformatter , "h:mm a" format , convert string using "hh:mm" format. check out date formatting guide familiarize material.
let dateasstring = "6:35 pm" let dateformatter = nsdateformatter() dateformatter.dateformat = "h:mm a" let date = dateformatter.datefromstring(dateasstring) dateformatter.dateformat = "hh:mm" let date24 = dateformatter.stringfromdate(date!)
Comments
Post a Comment