gpt4 book ai didi

ios - NsDate 格式化程序从字符串中给出错误的日期

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

<分区>

我有以下代码,它接受一个 NSString 并返回 NSDate。我从一个项目中复制了这段代码,它在其中运行得非常好——但是这给了我错误的输出

- (NSDate *)dateFromString:(NSString *)date
{
static NSDateFormatter *dateFormatter;
if (!dateFormatter)
{
dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"dd-MM-yyyy"];
}

NSLog(@"Date: %@ Formatted: %@",date,[dateFormatter dateFromString:date]);

return [dateFormatter dateFromString:date];
}

输出来自日志:

Date: 07-01-2014 Formatted: 2014-01-06 18:30:00 +0000
Date: 24-01-2014 Formatted: 2014-01-23 18:30:00 +0000
Date: 06-01-2014 Formatted: 2014-01-05 18:30:00 +0000
Date: 15-01-2014 Formatted: 2014-01-14 18:30:00 +0000
Date: 22-01-2014 Formatted: 2014-01-21 18:30:00 +0000
Date: 31-01-2014 Formatted: 2014-01-30 18:30:00 +0000
Date: 14-01-2014 Formatted: 2014-01-13 18:30:00 +0000
Date: 30-01-2014 Formatted: 2014-01-29 18:30:00 +0000

奇怪的是它也在改变日期..!!任何帮助...!!!

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