NSDateFormatter for BST instead of GMT+1

后端 未结 2 490
情深已故
情深已故 2021-01-17 04:30

I want to display the following string on my time axis:

\"GMT/BST\"

Here\'s the code:

 NSDateFormatter *dateformatter=[[NSDateFormatter alloc         


        
2条回答
  •  别那么骄傲
    2021-01-17 04:58

    Turns out there is a built in array of 48 time zone abbreviations (e.g. 'BST') in iOS.

    NSDictionary *tzDict = [NSTimeZone abbreviationDictionary]; 
    

    There is an array of 419 time zone names in this array (e.g. 'Europe/London'):

    NSArray *timeZoneNames = [NSTimeZone knownTimeZoneNames];
    

    tzDict contains the abbreviations for daylight saving time for a subset of time zone names. So the algorithm would be to check if we are in DST, then see if tzDict has an entry, and subsitute that or if not, use

    [NSTimeZone abbreviation];
    

    Here are a few other topics on time zones in general.

    Daylight saving time and time zone best practices

    How can I map tz database names to city and country names?

    C# british summer time (BST) timezone abbreviation

    http://en.wikipedia.org/wiki/List_of_tz_database_time_zones

    GMT timezone conversion in objective c

提交回复
热议问题