Ben
Ben

Reputation: 67

NSString to NSDate gives completely wrong data (tried including timezone)

Tried converting NSString with the date 'Saturday 22 August 2015 17:30' to NSDate but it comes out with '2014-12-27 17:30:00 UTC'. I don't even care that the format comes out wrong, i just want it to convert it to NSDate correctly.

currentFixtures.timeDate is a NSString containing 'Saturday 22 August 2015 17:30' fixtureDate is an NSDate that comes back with '2014-12-27 17:30:00 UTC'

 NSDateFormatter *dateFormatFixture = [[NSDateFormatter alloc]init];
 [dateFormatFixture setDateFormat:@"EEEE d MMMM YYYY HH:mm"];
 [dateFormatFixture setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en-GB"]];
 [dateFormatFixture setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]];


 NSDate *fixtureDate = [[NSDate alloc] init];
 fixtureDate = [dateFormatFixture dateFromString:currentFixture.timeDate];

Upvotes: 2

Views: 89

Answers (1)

Ben
Ben

Reputation: 67

EEEE d MMMM yyyy H:m works, thanks to maddy

Upvotes: 1

Related Questions