【代码笔记】iOS-获得现在的时间

一, 代码。

复制代码
- (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

 

原文地址:https://www.cnblogs.com/yang-guang-girl/p/7092637.html