addy
addy

Reputation: 29

NSdate Assuming wrong time zone

I am trying to convert the following string into an NSDate object:

NSString *str=@"25 May 2012 10:25:00";

NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setDateFormat:@"d MMM yyyy HH:mm:ss"];
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"asia/kolkata"]];
 NSDate *date = [dateFormatter dateFromString:str];


In console : date-->2012-05-25 04:55:00 +0000....it lags behind 5 hours and 30 minutes and assumes GMT timezone instead of Asia...Why it is so?

Upvotes: 1

Views: 798

Answers (2)

Saurabh Passolia
Saurabh Passolia

Reputation: 8109

if you are looking for India Timezone you should use: enter image description here

Upvotes: -1

Jim
Jim

Reputation: 5960

When you see an [NSDate description] printed in the console, it is always the corresponding time in GMT. If you use the same date formatter to convert the date back to a string, it should be in the specified time zone.

An [NSDate description] is what you see if you type

po date

or

po [date description]

or you use NSLog to send either one of these forms to the console.

Upvotes: 4

Related Questions