Re: Displaying time
Re: Displaying time
- Subject: Re: Displaying time
- From: Nathan Kinsinger <email@hidden>
- Date: Fri, 22 Aug 2008 04:32:58 -0600
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 (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