Search code examples
objective-ciostimezonensdateformatter

Parsing BST Timezone


I'm having problems parsing a date which has 'BST' as its timezone.

This is the date: 2012-04-22 16:00:00 BST

And this is my code

NSDateFormatter * formatter = [[NSDateFormatter alloc] init];
[formatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_GB"]];
[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss ZZZ"];
NSDate * matchDate = [formatter dateFromString:dateStr];

This works well with GMT for example, but for BST I'm getting nil, any clue?


Solution

  • BST is a date format considered a metazone, therefore you should parse it using the V syntax.

    I would suggest changing your parse string to:

    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss V"];
    

    the use of the quotes around the ZZZ, means that the parser should expect the text ZZZ, rather than a timezone