2
votes

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];
1
Use yyyy, not YYYY. And the locale should be en_GB, not en-DB. - rmaddy
check this post [get current date as DD/MM/YYYY][1] [1]: stackoverflow.com/questions/27790657/… - One Eyed Raven

1 Answers

1
votes

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