I am getting a time in UTC and it is timezone short name along with it. To get the timezone short name I have the code below but it is giving it as GMT +5.30. I want to be in the form of IST
For the US this is giving as an ADT, I need all the time zones to give 3 letters short name.
Is this possible?
Please check the code given below:
NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init]; [DateFormatter setDateFormat: @ "yyyy-MM-dd'THH: mm: ssssss"]; NSDate * sourceDate = [dateFormatter dateFromString: @ "2015-03-16T13: 08: 17.989Z"]; NSTimeZone * Destination Time Zone = [NSTimeZone Default Timezone]; NSString * str = [destinationTimeZone short]; NSDateFormatter * dateFormat = [[NSDateFormatter alloc] init]; [DateFormat setDateFormat: @ "MMMM dd yyyy, hH: mm"]; NSString * Local time = [dateFormat stringFromDate: sourceDate]; NSString * str1 = [NSString stringWithFormat: @ "% @,% @", local time, str]; NSLog (@ "local time:% @", str1);
Output is:
Local time: 16 March 2015, 18:38, GMT + 5: 30
I need it
Local time: 16 March 2015, 18:38, IST
Please help!
You can define the time zone of your date such as:
[DateFormat setTimeZone: DesiredTimeZone];
Then format it using the date format:
NSDateFormatter * formatter = [NSDateFormatter new]; Formatter.dateFormat = @ "DD MMM @ HH: MM Z";
Press z
property according to the time zone in the 03 letter format.
For more information
No comments:
Post a Comment