• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSDatePicker 24 hour clock (Daniel Wambold)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSDatePicker 24 hour clock (Daniel Wambold)


  • Subject: Re: NSDatePicker 24 hour clock (Daniel Wambold)
  • From: Wilfried Bernard <email@hidden>
  • Date: Sat, 16 Jan 2010 09:58:59 +0100

Hi,
I've read your post and in case you did not find a solution, this worked for me:
The trick is, you need to subclass NSDatePicker first like:

@interface TT24HourTimePicker : NSDatePicker {} @end

Then put the formatter in a new init phase of the implementation, like (use what ever format you like):

- (void)_init
{
	NSLocale*		my24HourLocale = [[[NSLocale alloc] initWithLocaleIdentifier:@"uk"] autorelease];
	NSDatePickerCell*	cell = [self cell];
	[cell setLocale:my24HourLocale];
	[cell setFormatter:[[[NSDateFormatter alloc] initWithDateFormat:@"%H:%M:%S" allowNaturalLanguage:NO] autorelease]];
	[cell setTitle:@"00:00:00"];
}

...and if you want to load it in awakeFromNib call the new _init with:

- (id)initWithCoder:(NSCoder*)coder
{
    self = [super initWithCoder:coder]; // NSDatePickerCell
    if (!self) {
        return nil;
    }

    // Common init
    [self _init];

    return self;
}

Hope this helps.

Cheers, Wilfried Bernard
On Jan 9, 2010, at 12:31 PM, email@hidden wrote:

> Hello. I have an NSDatePicker (NSTextFieldAndStepperDatePickerStyle) and I need it to display time in a 24-hour time mode. After reading Apple's docs and searching the Web, I can't seem to find a way to make this happen. I have attached an NSDateFormatter in IB and specified 24-hour time (HH:MM), but the program reverts back to a 12-hour clock. I changed my System Preferences to a 24 hour clock, but the NSDatePicker refuses to change. I tried a programmatic formatter:
>
> NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
> [dateFormatter setDateFormat:@"HH:mm"];
> [myDatePicker setFormatter:dateFormatter];
> (Also tried [[myDatePicker cell] setFormatter:dateFormatter];)
>
> In desperation, I set a loop trying every NSDatePickerElementFlags from 0 to 513. Have I missed something, or is a 24-hour clock not allowed? The program is for use in a location where 24-hour time is mandatory. Thanks for any insight you might have.
>
> Best Regards,
> Dan

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: Re: Adding to-many objects programmatically
  • Next by Date: Re: needing help w/ asynchronous message problem, using YAMessageQueue
  • Previous by thread: Re: NSURLRequest and NSOperationQueue
  • Next by thread: Accessing Variables from Multiple NIBs
  • Index(es):
    • Date
    • Thread