ios - How can i get formatted string of hour with no separators? -


i need nsstring nsdate, need hour,minutes , seconds. if it's 1:40:30 pm need string "134030"

nsdateformatter *usertimeformatter = [[nsdateformatter alloc] init]; [usertimeformatter setdateformat:@"hhmmss"]; 

this doesn't work. if use format hhmmss seems work it's not in 24 hour format. suggestions? might locale?

the reason behaviour locale, set correct locale, set local of nsdateformatter en_us_posix fix this. works both 24-hour , 12 hour format.

   nsdateformatter *usertimeformatter = [[nsdateformatter alloc] init];         [usertimeformatter setdateformat:@"hhmmss"];         nslocale *en_us_posix = [[nslocale alloc] initwithlocaleidentifier:@"en_us_posix"];         [usertimeformatter setlocale:en_us_posix];          nslog(@"time:%@",[usertimeformatter stringfromdate:usertime]); 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -