获取当前日期时间并以LCD形式显示
Ios代码
- (void)viewDidLoad {
[super viewDidLoad];
[self updateTime];
[NSTimer scheduledTimerWithTimeInterval:(1.0) target:self selector:@selector(updateTime) userInfo:nil repeats:YES];
}
-(void)updateTime
{
NSString *time = [self getCurrentTime];
timeLabel.text = time;
[timeLabel setFont:[UIFont fontWithName:@"DBLCDTempBlack" size:25.0]];
[timeLabel setTextAlignment:UITextAlignmentCenter];
[timeLabel setTextColor:[UIColor redColor]];
[self.view setBackgroundColor:[UIColor blackColor]];
}
- (NSString *) getCurrentTime{
NSDate *today = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
NSString *currentTime = [dateFormatter stringFromDate:today];
[dateFormatter release];
return currentTime;
}
相关新闻>>
- 发表评论
-
- 最新评论 更多>>