Need NSDatePicker to show GMT not local date/time

I have parsed a string into a date of format:

       NSDateFormatter     *   ndf = [[NSDateFormatter alloc] init];
       [ndf setDateFormat: @"yyyyDDDHHmmssz"];

Create a date, call it debugDate as NSString*:

_aDate = [ndf dateFromString: debugDate];

Set the flags for the NSDatePicker:

_dateDisplay.datePickerElements = NSHourMinuteSecondDatePickerElementFlag
                                 | NSTimeZoneDatePickerElementFlag
                                 | NSYearMonthDayDatePickerElementFlag
                                 | NSEraDatePickerElementFlag;
// put date in        
[_dateDisplay setDateValue: _aDate];

This works fine. Except that I need the date/time displayed in GMT and the date picker puts the correct date out in local time.

The debugDate is: @"1998156063541GMT"

This shows up as 1998 JUNE 04 11:35:41 which is correct for PDT.

How do I force a NSDatePicker GMT display?


TIA

ClarkW

When you want to use always GMT in your app put this line into your AppDelegate applicationDidFinishLaunching:


[NSTimeZone setDefaultTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"GMT"]];

That's almost certainly far too heavy of a hand to solve the question at hand. This will change the default time zone for all uses of time zones in your app which almost certainly will have unexpected side effects. Unless you truly need your entire app to be in GMT I would not do that.


To answer the original question, NSDatePicker has a timeZone property so you can simply set to GMT like:


_dateDisplay.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
Need NSDatePicker to show GMT not local date/time
 
 
Q