gpt4 book ai didi

iphone - 获取 dateformatter 的 nil 值

转载 作者:行者123 更新时间:2023-11-29 11:00:10 25 4
gpt4 key购买 nike

 NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];

dateFormatter.dateFormat = @"EEE, dd MM yyyy HH:mm:ss VVVV";

NSDateFormatter *df1 = [[NSDateFormatter alloc] init];

[df1 setDateFormat:@"yyyy-MM-dd HH:mm:ss ZZZ"];

NSString *dateString = @"Mon, 29 Apr 2013 01:00:49 +0000";

NSDate *date1= [dateFormatter dateFromString:dateString];

NSString *localDateString = [df1 stringFromDate:date1];

NSLog(@"localDateString=%@", localDateString);

当我使用常量 dateString 值时,它会给出正确的输出.. 当我从 xml paring value dateString 给出输入时返回 nil 值

最佳答案

也许您在字符串的开头或结尾有一些额外的空格。使用

比较两个字符串的长度
dateString.length;

otherDateString.length;

您还可以比较并查看这些字符串是否相等,方法是使用

[dateString isEqualToString:otherDateString];

这可能会返回 false。

关于iphone - 获取 dateformatter 的 nil 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16273264/

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