您好,匿名用户
随意问技术百科期待您的加入

NSDateFormatter的yyyy和YYYY到底什么区别

0 投票

问题如题目
我在文档里看到

A common mistake is to use YYYY. yyyy specifies the calendar year whereas YYYY specifies the year (of “Week of Year”), used in the ISO year-week calendar. In most cases, yyyy and YYYY yield the same number, however they may be different. Typically you should use the calendar year.

但是这个Week of Year和普通的到底什么区别,求举例

用户头像 提问 2014年 1月30日 @ Viktor 上等兵 (290 威望)
分享到:

1个回答

0 投票

在stackoverflow 找到了这样的回答:

Both results are correct, the difference is because the DateUtils.WeekOfTheYear function uses the ISO 8601 standard definition of a week. That is, a week is considered to start on a Monday and end on a Sunday.

Check this explanation about the Weeks Numbers in the ISO 8601 format.

If 1 January is on a Monday, Tuesday, Wednesday or Thursday, it is in week 01. If 1 January is on a Friday, Saturday or Sunday, it is in week 52 or 53 of the previous year (there is no week 00). 28 December is always in the last week of its year.

Also the Embarcadero online help for the DateUtils.WeekOfTheYear function says

....if the first calendar day of the year is a Friday, Saturday, or Sunday, then for the first three, two, or one days of the calendar year, WeekOfTheYear returns the last week of the previous year. Similarly, if the last calendar day of the year is a Monday, Tuesday, or Wednesday, then for the last one, two, or three days of the calendar year, WeekOfTheYear returns 1 (the first week of the next calendar year).

So due which the 01-01-2011 was Saturday this week is considered the week number 52 of the previous year.

And that also explains why the week number returned for today (19-10-2011) is 42 instead of 43.

ISO 8601 format的大概意思是:
如果一月1日是星期一,星期二,星期三或星期四,它是在01周。如果一月1日是星期五,星期六或星期日,它在前一年的52周或53周

出处:http://stackoverflow.com/questions/78...

希望能有帮助

用户头像 回复 2014年 1月30日 @ Fiddlesticks 上等兵 (242 威望)
提一个问题:

相关问题

0 投票
1 回复 65 阅读
用户头像 提问 2012年 12月1日 @ Trundle 上等兵 (301 威望)
0 投票
0 回复 24 阅读
用户头像 提问 2012年 12月1日 @ Aphrodite 上等兵 (185 威望)
+1 投票
1 回复 87 阅读
用户头像 提问 2013年 3月3日 @ hadoop 上等兵 (109 威望)
0 投票
1 回复 36 阅读
0 投票
1 回复 26 阅读
用户头像 提问 2012年 12月1日 @ Artemis 上等兵 (162 威望)

欢迎来到随意问技术百科, 这是一个面向专业开发者的IT问答网站,提供途径助开发者查找IT技术方案,解决程序bug和网站运维难题等。
温馨提示:本网站禁止用户发布与IT技术无关的、粗浅的、毫无意义的或者违法国家法规的等不合理内容,谢谢支持。

欢迎访问随意问技术百科,为了给您提供更好的服务,请及时反馈您的意见。
...