开发者

Local time on the iPhone

I need to display the exact local time开发者_如何学Go and the time should be running.

Please help, if possible with sample code or explanation.

Thanks.


This returns the current date with Time

[NSDate date];

Now you can use NStimer to fetch the time every one second and display it.

NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(displayTime) userInfo:nil repeats:NO];
//Time Interval is one second
-(void) displayTime
{

    NSDate *currentDate = [NSDate date];
    NSDateFormatter *timeFormatter = [[[NSDateFormatter alloc]init]autorelease];
    timeFormatter.dateFormat = @"HH:mm:ss a";
    NSString *dateString = [timeFormatter stringFromDate: currentDate];
    yourlabel.text = dateString;
    [timeFormatter release]
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜