gpt4 book ai didi

objective-c - 非常奇怪的日期转换

转载 作者:行者123 更新时间:2023-12-03 17:04:23 24 4
gpt4 key购买 nike

我可以在我的应用程序中看到非常奇怪的日期转换。这是代码:

theDateString = [theDateFormatter stringFromDate:date];

如果日期2007-12-31 00:00:00 +0100theDateString2008

但是如果日期是2004-12-31 00:00:00 +0100theDateString2004。

方法是NSDateFormatter中的- (NSString *)stringFromDate:(NSDate *)date,它是一个Mac应用程序。

NSDateFormatter 格式为:[theDateFormatter setDateFormat:@"Y"];

为什么?谢谢

最佳答案

您应该使用@"y"而不是@"Y",因为大写的“Y”根据“一年中的周”指定年份。 2007 年的第 52 周以 2008 年结束,因此它返回 2008 年而不是 2007 年。

更新:
请参阅:http://waracle.net/mobile/iphone-nsdateformatter-date-formatting-table/

关于objective-c - 非常奇怪的日期转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14359999/

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