NSDateFormatter的yyyy和YYYY到底什么区别

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

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和普通的到底什么区别,求举例

阅读 7k
1 个回答

在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...

希望能有帮助

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏