直接上代码
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <script type="text/javascript"> //判断某天是周几 IE9以上支持 function getMyDay(date) { var week; var num = date.getDay(); switch (num) { case 0: week = '周日'; break; case 1: week = "周一"; break; case 2: week = '周二'; break; case 3: week = "周三"; break; case 4: week = "周四"; break; case 5: week = '周五'; break; case 6: week = "周六"; break; } return week; } var w1 = getMyDay(new Date("2018-01-30")); document.write(w1); </script> </body> </html>