> > On Jan 8, 2010, at 3:12 PM, Daniel Wambold 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. >>
> This works for me. I always want UTC time zone and a 24 hour clock, > > NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] > autorelease]; > [dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]]; > [dateFormatter setDateFormat:@"yyyy/MM/dd' 'HH:mm:ss' UTC' "]; > mystring = [mystring stringByAppendingString:[dateFormatter > stringFromDate:date]]; > > Where date is an NSDate*. > > The capital HH should give you 24 hours time, as I understand it. Is it > possible that "[myDatePicker cell]" is failing to see your dateFormatter and > is using some default instead? > > > > david David- Thanks for your response. It looks like you're formatting an NSString with the date. That's fine, but I want the NSDatePicker itself to show 24 hour time. In other words, the UI element that is the date picker should show, next to its stepper, a 24 hour time, rather than an AM/PM time. That was why I tried telling both the NSDatePicker and the NSDatePickerCell to adopt the NSDateFormatter. If you have achieved this UI setup, I misunderstood your response, and would appreciate it if you would clarify how you formatted the DatePicker widget itself. Thanks! -Dan_______________________________________________ Cocoa-dev mailing list ([email protected]) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [email protected]
