On Aug 22, 2008, at 12:59 AM, Ron Fleckner wrote:

Hi,

I want to display the current time in a full screen window. I'm making my computer into a digital clock (for my own use). I've done it by using NSCalendarDate and extracting the hours, minutes, and seconds, formatting a string and displaying it. I use an NSTimer to update the display every half a second.

My question is: Is there a better way to display what is essentially the same as the menu bar clock?

Thanks for any ideas,

Ron

Look at NSDateFormatter.

Here's one way to do that.

IBOutlet NSTextField *theTextField;
NSDateFormatter *dateFormatter;

+ (void)initialize
{
[NSDateFormatter setDefaultFormatterBehavior:NSDateFormatterBehavior10_4];
}

- (void)updateClockTime
{
[theTextField setStringValue:[dateFormatter stringFromDate:[NSDate date]]];
}

- (void)startClock
{
        dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateStyle:NSDateFormatterNoStyle];
        [dateFormatter setTimeStyle:NSDateFormatterMediumStyle];
        
[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateClockTime) userInfo:nil repeats:YES];
}

--Nathan
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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]

Reply via email to