当前位置:编程学习 > wap >>

获取当前日期时间并以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;  

}   

 

 


作者 jsntghf
补充:移动开发 , IOS ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,