how can i display current time on a label iphone?
A:
Use an NSTimer to trigger regular calls to a method that updates the label.
Marcelo Cantos
2010-04-01 10:51:26
+4
A:
Ok. Here is something like you need.
Place an IBOutlet Label on your .h file of your view controller & connect in .xib file.
Now, just place following code in your .m file of view controller.
- (void)viewDidLoad
{
[super viewDidLoad];
// your label text is set to current time
lblTime.text=[[NSDate date] description];
// timer is set & will be triggered each second
[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(showTime) userInfo:nil repeats:YES];
}
// following method will be called frequently.
-(void)showTime{
lblTime.text=[[NSDate date] description];
}
sugar
2010-04-01 12:55:17
A:
If you have to format your date before showing it use the NSDateFormatter class.
schaechtele
2010-04-01 13:39:53