ios - get Timezone in format of UTC+5:30 -
i want timezone of user in string formatted utc+5:30
i have tried this.
nstimezone *timezone=[nstimezone localtimezone]; nslog(@"%@ || %@",timezone.abbreviation,timezone.name);
this gives me output. (but not getting time want)
ist || asia/kolkata
thanks
you can use nsdate formatter offset utc:
nsdateformatter *dates = [[nsdateformatter alloc]init]; [dates setdateformat:@"z"]; nslog(@"%@", [dates stringfromdate:[nsdate date]]);
this log: +0530 (+5:30)
if want in specific format can do:
nsdateformatter *dateformatter = [[nsdateformatter alloc]init]; [dateformatter setdateformat:@"z"]; nsstring *offetstring = [dateformatter stringfromdate:[nsdate date]]; nsstring *formattedstring = [nsstring stringwithformat:@"utc%@:%@",[offetstring substringwithrange:nsmakerange(0, 3)],[offetstring substringwithrange:nsmakerange([offetstring length] - 2, 2)]];
Comments
Post a Comment