【OC】年月日分割
作者:
鄒賢 | 来源:发表于
2016-11-08 11:28 被阅读0次 NSString *time = @"2016-11-08";
NSDateFormatter *fm = [[NSDateFormatter alloc] init];
fm.dateFormat = @"yyyy-MM-dd";
NSDate *date = [fm dateFromString:time];
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDateComponents *components = [calendar components:NSCalendarUnitYear |NSCalendarUnitMonth|NSCalendarUnitDay fromDate:date];
NSLog(@"\n%ld\n%ld\n%.02ld", (long)components.year, (long)components.month, (long)components.day);
运行结果
2016
11
08
本文标题:【OC】年月日分割
本文链接:https://www.haomeiwen.com/subject/rdyauttx.html
网友评论