Javascript 案件“2月”: 月=1; 打破 “mar”案: 月=2; 打破 案例“apr”: 月=3; 打破 “可能”一案: 月=4; 打破 案例“jun”: 月=5; 打破 案件“jul”: 月=6; 打破 案件“8月”: 月=7; 打破 案例“sep”: 月=8;
案件“2月”: 月=1; 打破 “mar”案: 月=2; 打破 案例“apr”: 月=3; 打破 “可能”一案: 月=4; 打破 案例“jun”: 月=5; 打破 案件“jul”: 月=6; 打破 案件“8月”: 月=7; 打破 案例“sep”: 月=8; 打破 案例“10月”: 月=9; 打破 案件“11”: 月=10; 打破 案例“dec”: 月=11; 打破 违约: var temp=新日期(); 如果(临时getDate()>9){ 月份=((临时getMonth()+1)==12)?11:(临时getMonth()+1); }否则{ month=temp.getMonth(); } 转换=真; 打破 } }else if(typeof month==“number”| |(typeof month==“string”&&&&!isNaN(parseInt(month))){ 月=(!已转换)?parseInt(月)-1:月; } if(typeof year==“string”&&&!isNaN(parseInt(year))| | typeof year==“number”){ 如果(parseInt(年)/1000>2){ 年=parseInt(年); }否则如果(parseInt(年)/10>=0&&parseInt(年)/10<10){ var temp2=新日期().getFullYear(); 年份=(帕西恩特(数学地板(temp2/100))*100)+帕西恩特(年份); } }else if(typeof year==“string”&&isNaN(parseInt(year))){ 如果(年份==“本”){ 年份=新日期().getFullYear(); }如果(年份==“上一个”){ 年份=新日期().getFullYear()-1; }否则,如果(年份==“下一年”){ 年份=新日期().getFullYear()+1; }否则{ console.warn('未识别年份字符串,返回到当前年份。'; 年份=新日期().getFullYear(); } } var日期=[]; //坚持住,这会有麻烦的 var d=新日期(), 道琼斯指数=[“太阳”、“周一”、“周二”、“周三”、“周四”、“周五”、“周六”], getDow=函数(sd、dowa){ 对于(变量i=0;iJavascript 案件“2月”: 月=1; 打破 “mar”案: 月=2; 打破 案例“apr”: 月=3; 打破 “可能”一案: 月=4; 打破 案例“jun”: 月=5; 打破 案件“jul”: 月=6; 打破 案件“8月”: 月=7; 打破 案例“sep”: 月=8;,javascript,Javascript,案件“2月”: 月=1; 打破 “mar”案: 月=2; 打破 案例“apr”: 月=3; 打破 “可能”一案: 月=4; 打破 案例“jun”: 月=5; 打破 案件“jul”: 月=6; 打破 案件“8月”: 月=7; 打破 案例“sep”: 月=8; 打破 案例“10月”: 月=9; 打破 案件“11”: 月=10; 打破 案例“dec”: 月=11; 打破 违约: var temp=新日期(); 如果(临时getDate()>9){ 月份=((临时getMonth()+1)==12)?1
d.setDate(d.getDate()+(9-d.getDay())%7)
;)第一个循环可以替换为非迭代的d.setDate(d.getDate()+(9-d.getDay())%7)
;)
<!DOCTYPE html>
<html>
<head>
<script>
function displayDate()
{
var myDate = new Date();
myDate.setHours(19, 00, 0, 0);
myDate.setYear(2013);
myDate.setDate(1);
myDate.setMonth();
//Find Tuesday
var tue = 2;
while(myDate.getDay() != tue) {
myDate.setDate(myDate.getDate() + 1);
}
document.write(myDate);
</script>
</head>
<body>
<h1>My First JavaScript</h1>
<p id="demo">This is a paragraph.</p>
<button type="button" onclick="displayDate()">Display Date</button>
</body>
</html>
function getTuesday() {
var datenow = new Date();
var d = new Date(),
month = d.getMonth(),
tuedays= [];
d.setDate(1);
// Get the first Monday in the month
while (d.getDay() !== 2) {
d.setDate(d.getDate() + 1);
}
// Get all the other Tuesdays in the month
while (d.getMonth() === month) {
tuedays.push(new Date(d.setHours(17,00,00,00)));
d.setDate(d.getDate() + 7);
}
If (d.getDate() >= datenow.getDate)
{
d.setMonth(d.getMonth() + 1);
document.write(tuedays[1]);
}
Else
{
document.write(tuedays[1]);
}
}
function getTuesday() {
var d = new Date(),
month = d.getMonth(),
tuesdays= [];
d.setDate(1);
// Get the first Monday in the month
while (d.getDay() !== 2) {
d.setDate(d.getDate() + 1);
}
// Get all the other Tuesdays in the month
while (d.getMonth() === month) {
tuesdays.push(new Date(d.getTime()));
d.setDate(d.getDate() + 7);
}
return tuesdays;
}
function getDates(dayString, month, year, first, allInYear) {
if (!dayString) { console.error('Missing required parameter: dayString is required.'); return; }
if (first === undefined || first === null) { first = false; }
if (allInYear === undefined || allInYear === null) { allInYear = false; }
if (year === undefined || year === null) { year = new Date().getFullYear(); }
var converted = false;
if (month === undefined || month === null) {
var temp = new Date();
if (temp.getDate() > 9) {
month = ((temp.getMonth() + 1) == 12) ? 11 : (temp.getMonth() + 1);
} else {
month = temp.getMonth();
}
converted = true;
}
if (typeof month === "string" && isNaN(parseInt(month))) {
month = month.toLowerCase().substring(0, 3);
switch (month) {
case "jan":
month = 0;
break;
case "feb":
month = 1;
break;
case "mar":
month = 2;
break;
case "apr":
month = 3;
break;
case "may":
month = 4;
break;
case "jun":
month = 5;
break;
case "jul":
month = 6;
break;
case "aug":
month = 7;
break;
case "sep":
month = 8;
break;
case "oct":
month = 9;
break;
case "nov":
month = 10;
break;
case "dec":
month = 11;
break;
default:
var temp = new Date();
if (temp.getDate() > 9) {
month = ((temp.getMonth() + 1) == 12) ? 11 : (temp.getMonth() + 1);
} else {
month = temp.getMonth();
}
converted = true;
break;
}
} else if (typeof month === "number" || (typeof month === "string" && !isNaN(parseInt(month)))) {
month = (!converted) ? parseInt(month) - 1 : month;
}
if (typeof year === "string" && !isNaN(parseInt(year)) || typeof year === "number") {
if (parseInt(year) / 1000 > 2) {
year = parseInt(year);
} else if (parseInt(year) / 10 >= 0 && parseInt(year) / 10 < 10) {
var temp2 = new Date().getFullYear();
year = (parseInt(Math.floor(temp2 / 100)) * 100) + parseInt(year);
}
} else if (typeof year === "string" && isNaN(parseInt(year))) {
if (year === "this") {
year = new Date().getFullYear();
} else if (year === "last") {
year = new Date().getFullYear() - 1;
} else if (year === "next") {
year = new Date().getFullYear() + 1;
} else {
console.warn('Year string not recognized, falling back to current year. (this, last, next).');
year = new Date().getFullYear();
}
}
var dates = [];
//hang in there this is going to get a doosie
var d = new Date(),
dow = ["sun", "mon", "tue", "wed", "thu", "fri", "sat"],
getDow = function(sd, dowa) {
for (var i = 0; i < dowa.length; i++) {
var day = dowa[i];
if (sd.toLowerCase().substring(0, 3) == day) {
return i;
}
}
return -1;
},
di = getDow(dayString, dow),
getDIM = function(year, mon) {
var isLeap = ((year % 4) == 0 && ((year % 100) != 0 || (year % 400) == 0));
return [31, (isLeap ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][mon];
};
d.setFullYear(year);
d.setMonth(month, 1);
if (di == -1) { console.error('Range Error: Day of the week should be between sunday and saturday'); return; }
if (first && !allInYear) {
while (d.getDay() !== di) {
d.setDate(d.getDate() + 1);
}
return d;
} else if (first && allInYear) {
var tm = 0;
d.setMonth(tm, 1);
for (var i = tm; i <= 11; i++) {
while (d.getDay() !== di) {
d.setDate(d.getDate() + 1);
}
dates.push(new Date(d));
tm += 1;
d.setMonth(tm, 1);
}
return dates;
} else if (!first && !allInYear) {
var eom = getDIM(d.getFullYear(), d.getMonth());
for (var x = 1; x <= eom; x++) {
if (d.getDay() === di) {
dates.push(new Date(d));
}
d.setDate(d.getDate() + 1);
}
return dates;
} else if (!first && allInYear) {
var tm = 0;
for (var i = 0; i <= 11; i++) {
var eom = getDIM(d.getFullYear(), i),
dim = [];
d.setMonth(i, 1);
for (var x = 1; x <= eom && d.getMonth() == i; x++) {
if (d.getDay() === di) {
dim.push(new Date(d));
}
d.setDate(d.getDate() + 1);
}
dates.push(dim);
}
return dates;
} else {
return [];
}
}