ios - NSDateFormatter的yyyy和YYYY到底什么区别
PHPz
PHPz 2017-04-17 11:32:58
0
1
657

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

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

PHPz
PHPz

学习是最好的投资!

reply all(1)
洪涛

I found this answer on 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 roughly means:
If January 1st falls on Monday, Tuesday, Wednesday or Thursday, it is in week 01. If January 1st falls on a Friday, Saturday or Sunday, it is in week 52 or 53 of the previous year

Source: http://stackoverflow.com/questions/78...

Hope this helps

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template