1

I have tried setting the timezone and locale of the NSDateFormatter but I can't seem to get anything to work. Here is the code

NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"MM/dd/yyyy hh:mm:ss"];
NSString *myFireDateString=[@"9/17/11" stringByAppendingString:@" 09:00:00"];
NSDate *myFireDate = [dateFormat dateFromString:myFireDateString];  
NSLog(@"The datestring is is %@",myFireDateString);
NSLog(@"The formatted date is %@",myFireDate);

Here is the output:

The datestring is is 9/17/11 09:00:00

The formatted date is 2011-09-17 13:00:00

Eric
  • 11
  • 2

1 Answers1

0

You need to set a timezone to your dateFormatter:

[dateFormatter setTimeZone:[NSTimeZone defaultTimeZone];

See NSDate from NSString , shows the previous day

Community
  • 1
  • 1
Philippe
  • 905
  • 6
  • 18