gpt4 book ai didi

ios - 将日期字符串 (2016-04-27T08 :06:07. 531Z) 转换为特定日期格式 dd.MM.YYYY

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:56:58 25 4
gpt4 key购买 nike

我有 2016-04-27T08:06:07.531Z 格式的日期字符串,想转换为 2016.04.27。我试过下面的代码

NSString *dateString = @"2016-04-27T08:06:07.531Z";

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-ddTHH:mm:ss.Z"];

NSDate *dateReceived = [dateFormatter dateFromString:dateString];
[dateFormatter setDateFormat:@"dd.MM.YYYY"];

NSString *dateReq = [dateFormatter stringFromDate:dateReceived];

NSLog(@"Date Req:%@",dateReq);

我在 NSLog 的控制台中得到 null。任何帮助将不胜感激。谢谢。

最佳答案

像这样使用

NSString *dateString = @"2016-04-27T08:06:07.531Z";
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];

[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSZ"];

NSDate *dateReceived = [dateFormatter dateFromString:dateString];
// 2016.04.27
[dateFormatter setDateFormat:@"yyyy.MM.dd"];

NSString *dateReq = [dateFormatter stringFromDate:dateReceived];

NSLog(@"Date Req:%@",dateReq);

enter image description here

关于ios - 将日期字符串 (2016-04-27T08 :06:07. 531Z) 转换为特定日期格式 dd.MM.YYYY,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36907651/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com