Nothing is going wrong, a NSDate
instance will never have a timezone ( well it will but it is always GMT, indicated by the +0000
timezone in the date description).
What you are telling dateformatter in your code is that the timezone of the date you want to parse is Asia/Kolkata
but you want it to be GMT
.
First you need to make a NSDate
object from the input date string with the time zone set to the correct time zone, GMT
as you indicated.
NSTimeZone *gmtTimeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
[dateFormatter setTimeZone:sourceTimeZone];
NSDate *dateFromString = [dateFormatter dateFromString:timeStamp];
NSLog(@"Input date as GMT: %@",dateFromString);
Then when you present the date as an string use :
NSTimeZone* sourceTimeZone = [NSTimeZone timeZoneWithName:@"Asia/Kolkata"];
[dateFormatter setTimeZone:sourceTimeZone];
NSString *dateRepresentation = [dateFormatter stringFromDate:dateFromString];
NSLog(@"Date formated with local time zone: %@",dateRepresentation);