一, 代碼。
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//獲得現在的時間
[self currentTime];
}
#pragma -mark -functions
//計算現在的時間
- (void)currentTime
{
//時間格式
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
//現在時間
NSDate * currentdate = [NSDate date];
NSString * currentDateString = [dateFormatter stringFromDate: currentdate];
NSLog(@"---currentDateString--%@",currentDateString);
}
二,輸出。
2015-10-23 10:15:24.928 計算現在的時間[1607:61610] ---currentDateString--2015-10-23 10:15:24
以上所述是小編給大家介紹的iOS 獲得現在的時間代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對本站網站的支持!