美文网首页
获取当前时间的两种方式

获取当前时间的两种方式

作者: 鄂北 | 来源:发表于2018-08-21 16:58 被阅读12次

在这里记录下获取当前时间的两种方式,方便以后查询

第一种方式:

NSDate * currentDate = [NSDate date];
    NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"YYYY/MM/dd HH:mm:ss"];
    NSString * time = [dateFormatter stringFromDate:currentDate];

第二种方式:

NSDate * currentDate = [NSDate date];
    NSString * time = [currentDate stringWithFormat:@"YYYY-MM-dd"];

这里需要注意的是月份MM得大写,分钟mm小写,这是为了区分月份和分钟的。
天dd小写,小时HH大写,秒ss小写

相关文章

网友评论

      本文标题:获取当前时间的两种方式

      本文链接:https://www.haomeiwen.com/subject/bcyjiftx.html