• 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: Displaying time
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Displaying time
      • From: Ron Fleckner <email@hidden>
References: 
 >Displaying time (From: Ron Fleckner <email@hidden>)

  • Prev by Date: Re: File Extensions Problem
  • Next by Date: Re: Displaying time
  • Previous by thread: Displaying time
  • Next by thread: Re: Displaying time
  • Index(es):
    • Date
    • Thread