objective c - iOS 9 : Add GMT Time Value -
i had search on google how gmt time in objective-c, , got :
+ (nsstring *)getgmttime{ nsdateformatter *dateformatter = [[nsdateformatter alloc] init]; dateformatter.dateformat = @"yyyy-mm-dd't'hh:mm"; nstimezone *gmt = [nstimezone timezonewithabbreviation:@"gmt"]; [dateformatter settimezone:gmt]; return [dateformatter stringfromdate:[nsdate date]];}
is there way add or set gmt time ? (gmt+5)
the flexible way use timezoneforsecondsfromgmt
. more typo proof using strings gmt+x.
here fuly working example:
+ (nsstring *)getgmttime{ nsdateformatter *dateformatter = [[nsdateformatter alloc] init]; dateformatter.dateformat = @"yyyy-mm-dd't'hh:mm"; nstimezone *gmt = [nstimezone timezoneforsecondsfromgmt:(60*60*5)]; [dateformatter settimezone:gmt]; return [dateformatter stringfromdate:[nsdate date]]; }
it returns 2016-08-29t12:13 (when gmt time 2016-08-29t7:13)
note: 60*60*5
means 5 hours x 60 minutes x 60 seconds
Comments
Post a Comment