没有合适的资源?快使用搜索试试~ 我知道了~
iOS移动应用开发 iOS 获取日期的年月日(OC).pdf
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 62 浏览量
2022-07-06
21:56:52
上传
评论
收藏 33KB PDF 举报
温馨提示
试读
2页
iOS移动应用开发 iOS 获取日期的年月日(OC).pdf 学习资料 复习资料 教学资源
资源推荐
资源详情
资源评论
iOS 获取日期的年、月、日
转载自 https://blog.csdn.net/u012198553/article/details/53641759
#pragma mark - 获取特定的时间
-(NSString *)getDateSubTimes {
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *comps = [[NSDateComponents alloc] init];
NSInteger unitFlags = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay |
NSCalendarUnitWeekday |
NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
comps = [calendar components:unitFlags fromDate:[NSDate date]];
NSInteger year=[comps year];
NSInteger week = [comps weekday];
NSInteger month = [comps month];
NSInteger day = [comps day];
NSInteger hour = [comps hour];
NSInteger min = [comps minute];
NSInteger sec = [comps second];
NSString *yearStr = [NSString stringWithFormat:@"%ld",(long)year];
NSString *monthStr = [NSString stringWithFormat:@"%ld",(long)month];
if (monthStr.length != 2) {
monthStr = [NSString stringWithFormat:@"0%@",monthStr];
}
NSString *dayStr = [NSString stringWithFormat:@"%ld",(long)day];
if (dayStr.length != 2) {
dayStr = [NSString stringWithFormat:@"0%@",dayStr];
}
NSString *hourStr = [NSString stringWithFormat:@"%ld",(long)hour];
if (hourStr.length != 2) {
hourStr = [NSString stringWithFormat:@"0%@",hourStr];
}
NSString *minStr = [NSString stringWithFormat:@"%ld",(long)min];
if (minStr.length != 2) {
minStr = [NSString stringWithFormat:@"0%@",minStr];
}
NSString *secStr = [NSString stringWithFormat:@"%ld",(long)sec];
if (secStr.length != 2) {
secStr = [NSString stringWithFormat:@"0%@",secStr];
}
NSString *str = [NSString
资源评论
努力搬砖的小王
- 粉丝: 16
- 资源: 7706
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功