• 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
NSDate, NSTimer, NSTimeInterval combined question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSDate, NSTimer, NSTimeInterval combined question


  • Subject: NSDate, NSTimer, NSTimeInterval combined question
  • From: Eric Lee <email@hidden>
  • Date: Sat, 2 Aug 2008 00:31:08 -0500

I'm making a StopWatch, and I'm just a beginner, so please be patient with me.

I have two tabs. The first tab is a timer, while the second tab is a clock in string format. I have a few problems with both of them.

The problem with the timer is that it starts from January 1st, 2001. How can I modify my code so that it'll start from 0, and then go upwards (1, 2, 3, 4, 5, 6, 7, etc...)?

I'll post my code below.

The problem with the clock is that it can post the time in string format, but it won't update every minute after that. I also use awakeFromNib to post it, because, like i said, I'm just a beginner (first programming language also).

Here's the code for the timer:

- (IBAction)startWatch:(id)sender

{
	NSDate *currentDate = [NSDate date];

timer = [NSTimer timerWithTimeInterval:0 target:self selector:@selector(updateTextfield:) userInfo:nil repeats: YES];
[[NSRunLoop currentRunLoop] addTimer:timer forMode: NSDefaultRunLoopMode];
[timer setFireDate:currentDate];
[timer retain];
}



- (void)updateTextfield:(NSTimer *)timer

{

	NSTimeInterval now = [NSDate timeIntervalSinceReferenceDate];

	NSTimeInterval startTime;

	NSTimeInterval difference = now - startTime;

	NSString *timeString = [NSString stringWithFormat:@"%f", difference];

	[textField setStringValue:timeString];
}


Here's the code for the clock:

- (void)awakeFromNib
{
	NSDate *someDate = [NSDate date];
	NSTimer *anotherTimer = [NSDate date];

	[clock setStringValue:anotherTimer];
}


Thanks to everyone! _______________________________________________

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: NSDate, NSTimer, NSTimeInterval combined question
      • From: Ron Fleckner <email@hidden>
  • Prev by Date: Re: NSPopupButton and Interface Builder
  • Next by Date: IKImageBrowser drag reordering question/problem
  • Previous by thread: Re: NSPopupButton and Interface Builder
  • Next by thread: Re: NSDate, NSTimer, NSTimeInterval combined question
  • Index(es):
    • Date
    • Thread