ios - How can I get the date in 24 hours format -


nsdate *localdate = [nsdate date]; nstimeinterval timezoneoffset = [[nstimezone systemtimezone] secondsfromgmtfordate:localdate]; nsdate *gmtdate = [localdate datebyaddingtimeinterval:-timezoneoffset]; 

this gives me time in 12 hours format. so, example is 2.15 pm. gives me 2016-01-16 02:15:00 +0000.

however, want in 24 hours format 14:15:00. want time. how can that.

if need string represents time in format need, try use nsdateformatter setting gmt timezone , desired dateformat (hh:mm:ss in case)

    nsdateformatter *formatter = [[nsdateformatter alloc] init];     [formatter setdateformat:@"hh:mm:ss"];     [formatter settimezone:[nstimezone timezonewithabbreviation:@"gmt"]];     nslog(@"current time in gmt = %@", [formatter stringfromdate:[nsdate date]]); 

this print time in format 12:34:56 in gmt timezone

for more info on date formats see this fine article


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -