在标准组件Delphi Win32的调色板中有组件MonthCalendar,其属性为WeekNubers = true(显示周数),date = now,第一天 – 星期一.
显示19号码(今天) – 星期43号.
我通过dateutils.WeekOfTheYear(now)=请求号码返回42.
来源(0.5 Mb)http://www.sendspace.com/file/yuz6ko
通过组件MonthCalendar的初始代码判断 – 就像所有它都是真的(即使不暴露一周的第一天,它从系统参数中获取值).
并在询问WeekOfTheYear它被告知,所有被认为也是标准的ISO应用,但数字不重合:(
无论如何,我不明白,一周消失 – 如果要查看日历,应该是43,如果考虑,那个星期53和去年的第一个问题……
顺便说一下,2011年1月1日的WeekOfTheYear也会回来52但是应该返回1 …
为什么区别和哪里是正确的?
解决方法
DateUtils.WeekOfTheYear
功能使用了一周的ISO 8601标准定义.也就是说,一周被认为是在星期一开始,在星期日结束.
请查看此explanation关于ISO 8601格式的周数.
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.
此外,DateUtils.WeekOfTheYear
功能的Embarcadero在线帮助说
….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,
or Wednesday,then for the last one,or three days of the
calendar year,WeekOfTheYear returns 1 (the first week of the next
calendar year).
因此,01-01-2011本周六是本周被认为是上一年的第52周.
这也解释了为什么今天(19-10-2011)返回的周数是42而不是43.