gpt4 book ai didi

ios - NSDateFormatter 设置日期格式 : What's the difference between "DD" and "dd"?

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:22:51 29 4
gpt4 key购买 nike

使用 NSDateFormatter 解析日期。下面的日期是 2013 年 5 月 2 日。我得到不同的结果(如下所示)取决于我是否在 dateFormat 字符串中使用“DD”和“dd”

NSString * dateStr = @"2013-05-02";
NSDateFormatter * dateFormat = [NSDateFormatter new];
[dateFormat setDateFormat:@"yyyy-MM-DD"];
NSDate * date = [dateFormat dateFromString:dateStr];
NSLog(@"%@",[dateFormat stringFromDate:date]);
//logs 2013-01-02 ** incorrect
[dateFormat setDateFormat:@"yyyy-MM-dd"];
//logs 2013-05-02 ** correct

“DD”在做什么?它有什么作用吗?

我一直在网上寻找这些日期格式字符串的权威指南,但我还没有找到。如果有人知道,请告诉我。

谢谢

最佳答案

dd 是月中的第几天,DD 是一年中的第几天。

参见 http://developer.apple.com/library/ios/ipad/#documentation/cocoa/Conceptual/DataFormatting/Articles/dfDateFormatting10_4.html

该文档根据操作系统的版本链接到不同的标准。适用于 iOS 6 的是 tr35-25:http://www.unicode.org/reports/tr35/tr35-25.html#Date_Format_Patterns

关于ios - NSDateFormatter 设置日期格式 : What's the difference between "DD" and "dd"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17118050/

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