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

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -