objective c - NSString to NSDate returns wrong date -


I try to change my NSString to NSDate object , But NSDateFormatter gives me a weird price.

Here is the code:

  NSDateFormatter * dateFormat = [[NSDateFormatter alloc] init]; [DateFormat setDateFormat: @ "yyyy-MM-dd HH: mm"]; NSDate * date = [dateFormat dateFromString: @ "2012-08-15 00:00"]; [DateFormat release];   

date is value 2012-08-14 21:00 +0000 . This is the difference of 3 hours between the NSString value and the NSDate value. I think I have forgotten something, but I do not know what is

This is what I Experiment:

  NSDateFormatter * dateFormat = [[NSDateFormatter alloc] init]; [DateFormat setDateFormat: @ "yyyy-MM-dd HH: mm: SSZZZ"]; NSDT * date = [dateformat detfrostring: @ "2012-08-15 00:00:00 +0000"]; NSLog (@ "\ n \ n DATE:% @ \ n \ n \ n", date);   

+0000 is the timezone, so make sure that you use your timezone, such as +0400 .

EDIT: If you can not change the string, then you can use this code to do this:

  NSDateFormatter * dateFormat = [[NSDateFormatter alloc] Init]; [DateFormat setDateFormat: @ "yyyy-MM-dd HH: mm"]; [DateFormat SettimeJohn: [nystimjon timezonefoursecondframmmt: 0]]; NSDate * date = [dateFormat dateFromString: @ "2012-08-15 00:00"];    

Comments