views:

129

answers:

3

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
+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
A: 

If you have to format your date before showing it use the NSDateFormatter class.

http://developer.apple.com/iphone/library/documentation/Cocoa/Reference/Foundation/Classes/NSDateFormatter_Class/Reference/Reference.html

schaechtele