gpt4 book ai didi

objective-c - NSDateFormatter BC/AD日期发行

转载 作者:行者123 更新时间:2023-12-01 16:53:49 25 4
gpt4 key购买 nike

我试图弄清楚如何使用NSDateFormatter解析AD和BC日期,以及为什么0000 year解析失败。

NSString *test1 = @"0000-01-01";
NSString *test2 = @"0001-01-01";
NSString *test3 = @"0002-01-01 AD";
NSString *test4 = @"0002-01-01 BC";

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

[formatter1 setDateFormat: @"yyyy-MM-dd"];

NSLog(@"test 1 - %@", [formatter1 dateFromString: test1]);
NSLog(@"test 2 - %@", [formatter1 dateFromString: test2]);

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

[formatter2 setDateFormat: @"yyyy-MM-dd G"];

NSLog(@"test 3 - %@", [formatter2 dateFromString: test3]);
NSLog(@"test 4 - %@", [formatter2 dateFromString: test4]);

这就是返回的内容:
2012-11-26 11:24:27.536 Test[1968:c07] test 1 - (null)
2012-11-26 11:24:28.615 Test[1968:c07] test 2 - 0001-12-31 22:21:00 +0000
2012-11-26 11:24:37.604 Test[1968:c07] test 3 - 0001-12-31 22:21:00 +0000
2012-11-26 11:24:45.738 Test[1968:c07] test 4 - 0003-12-31 22:21:00 +0000

如您所见,对于0000日期,它返回null;对于其他变量,它返回错误的日期。

最佳答案

根据wikipedia,通常在公历及其前身朱利安历法中用来对年份进行编号的Anno Domini(AD)系统中不存在零年。在此系统中,公元前1年紧随其后是公元1。但是,天文年编号(与公元前1年的儒略年相一致)和ISO 8601:2004(公历年中的相符)存在零年。公元前1年)以及所有佛教和印度教历法。

您不能正确记录日期对象。尝试使用stringFromDate函数将获取的日期转换为字符串,然后记录输出。

关于objective-c - NSDateFormatter BC/AD日期发行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13561912/

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