JavaScript 求解某日期为一年中的第几周.doc

JavaScript 求解某日期为一年中的第几周.doc

  1. 1、本文档共37页,可阅读全部内容。
  2. 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
JavaScript 求解某日期为一年中的第几周 导读:就爱阅读网友为您分享以下“JavaScript 求解某日期为一年中的第几周”的资讯,希望对您有所帮助,感谢您对92的支持! 来源:Oracle里有select to_char(to_date(#39;2013-03-18#39;,#39;yyyy-MM-dd#39;),#39;iw#39;) from dual;可求某日期属于第几周(ISO 周),今用JavaScript实现之(包括它的逆运算)本算法参考ISO周的维基百科:/wiki/ISO_week_date测试环境:win7+Chrome24.0lt;script language=quot;javascriptquot;gt; // Calculating the week number of a given datefunction getWeek(date){var result=null;var array=[0,31,59,90,120,151,181,212,243,273,304,334];var month=date.getMonth();var weekday= date.getDay()==0?7:date.getDay();var year=date.getFullYear();var tmp=array[month]+date.getDate()+10-weekday;if(monthgt;1amp;amp;isLeapYear(year)){tmp++;}//If the week number thus obtained equals 0, it means that the given //date belongs to the preceding (week-based) year. If a week number //of 53 is obtained, one must check that the date is not actually//in week 1 of the following year.if(tmplt;7){if(isLeapYear(year-1)){result=parseInt((tmp+366)/7);}else{result=parseInt((tmp+365)/7);}}else{result=parseInt(tmp/7);if(53==result){result=checkIs53thWeek(date)?53:1;}}return result;}/*** Number of ISO weeks in an ISO year* The 53-week ISO week-numbering years can be described by any of the following equivalent definitions:* years with the dominical letter ED, D, or DC;* all years starting on Thursday, and leap years starting on Wednesday;* all years ending on Thursday, and leap years ending on Friday;* years in which either 1 January or 31 December is a Thursday (in leap years), or in which both are Thursdays (in common years).* All other week-numbering years have 52 weeks.*/function checkIs53thWeek(date){//Years in which either 1 January or 31 December is a Thursday (in leap years), or in which both are Thursdays (in common years).var jan1=new Date(date.getFullYear(),0,1);var dec31=new Date(date.getFullYear(),11,31);if(jan1.getDay()==4||dec31.getDay()==4){return true;}return false;}function isLeapYear(year){return ( year%4 == 0 ) amp;amp; (( year%100 != 0 ) || ( year%40

文档评论(0)

raojun00007 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档