First, you need to understand an international standard: ISO8601, which is the International Organization for Standardization (ISO) notation for defining dates and times, which is the representation of data storage and interchange, information exchange, date and time. The calculations for the first few weeks are described on the wiki as follows:
The calendar week and day notation can be expressed in 2 digits for the calendar week of the year, plus a number representing the day of the calendar week, but a capital letter W should be added before the calendar week, as May 3, 2004 may be written as 2004-w17-3 or 2004w173. The week of January 4 is the first week of the year, for example: January 1, 2005 is 2004-w53-6,2005 January 3 is 2005-w01-1. Each calendar week starts from Monday, and Sunday is the 7th day.
in the above description, there are two areas to focus on:1. Each calendar week starts from Monday, and Sunday is the seventh day. 2. The week of January 4 is the first one weeks of the year. Both of these can be used as a theoretical basis for today's first few weeks of the year.
In the jquery UI DatePicker, find the following function Iso8601week ():
/* Set as Calculateweek to determine the week of the year based on the ISO 8601 definition. * @param date date-the Date week for * @return number-the number of the week within INS this date/iso8601week:function (date) {var time, checkdate = new Date (Date.gettime ());
Find Thursday the this week starting on Monday checkdate.setdate (checkdate.getdate () + 4-(Checkdate.getday () | | 7));
Time = Checkdate.gettime (); Checkdate.setmonth (0); Compare with 1 checkdate.setdate (1); Return Math.floor (Math.Round (time-checkdate)/86400000)/7) + 1; }
The difficulty lies in the calculation of the span of the year, but combined with the above ISO8601 rules, it is easy to get a clear idea of jQueryUI.
If January 4 is Monday, then the 1,2,3 is the last week of last year. If January 4 is Tuesday, then, 1, 2nd is the last week of last year. If January 4 is Wednesday, then, number 1th is the last week of last year. If January 4 is Thursday, then Monday is the beginning. If January 4 is Friday, it will occupy the last day of last year. If January 4 is Saturday, the last two days of last year will be overrun. If January 4 is Sunday, the last three days of last year will be overrun.
This shows that you can infer that the current date belongs to the first few weeks, based on the Thursday of the current date. Based on the Thursday and this year's January 1 comparison, the current date belongs to the first few weeks of the year, the jquery algorithm is completely this idea. With this, we can easily use any language we want to calculate the current week is the first few weeks.
Author Chen (enthusiastic Pm\oracle\java etc, welcome peer Exchange) email:ziwen@163.com qq:409020100.
<!doctype html> The code above can be used as a test.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.