最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
iOS解析带T的时间字符串的详解
时间:2022-06-25 23:32:34 编辑:袖梨 来源:一聚教程网
现有从服务器获取到的时间字符串:
@”2016-12-05T12:21:37″
这个和一般获取到的时间字符串不同之处是:中间有T。
从这种字符串获取NSDate方法如下:
1.
NSDateFormatter *dateFormatter = [NSDateFormatter new];
dateFormatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ss";//使用带有子字符串'T'的日期格式
NSDate *date = [dateFormatter dateFromString:@"2016-12-05T12:21:37"];
2.
NSMutableString *mutableStringWithT = [[NSMutableString alloc] initWithString:@"2016-12-05T12:21:37"];
[mutableStringWithT replaceCharactersInRange:[mutableStringWithT rangeOfString:@"T"] withString:@" "];//手动将带T的时间字符串替换为@" "
NSDateFormatter *dateFormatter = [NSDateFormatter new];
dateFormatter.dateFormat = @"yyyy-MM-dd HH:mm:ss";//不带'T'的日期格式
NSDate *date = [dateFormatter dateFromString:mutableStringWithT];
相关文章
- 《崩坏:星穹铁道》缇宝最强光锥搭配推荐一览 02-20
- 《仙剑世界》潮起介绍 02-20
- 《崩坏:星穹铁道》如果时间是一朵花突破材料汇总 02-20
- 雨水节气的到来,标志着哪个季节的开始 02-20
- 《龙族:卡塞尔之门》活动日历查看位置 02-20
- 《仙剑世界》卡池抽取攻略 02-20