您的位置:首页 > 其它

iphone获取当前时间

2012-03-29 09:33 183 查看
-(void)GetTime:(id)sender
{
NSAutoreleasePool *pool = [[NSAutoreleasePool
alloc] init];
NSDateFormatter *formatter =[[NSDateFormatter
alloc] init];
NSDate *date = [[NSDate
alloc]init];
[formatter setTimeStyle:NSDateFormatterMediumStyle];
[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss "];//mm
NSTimeZone* timeZone = [NSTimeZone
timeZoneWithName:@"Asia/Shanghai"];
[formatter setTimeZone:timeZone];
NSString *locationtime = [formatter
stringFromDate:date];
currenttime = locationtime;
CurrenttimeLabel.text =
currenttime;
CurrenttimeLabel.enabled =
NO;
[date release];
[formatter release];
[pool release];
}

- (void)viewDidLoad
{
[NSThread detachNewThreadSelector:@selector(Gettime:)toTarget:selfwithObject:nil];

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: