js Method for Calculating the Day of the Week of the System's Current Date

  • 2021-07-02 23:35:48
  • OfStack

In this paper, we share four methods for calculating the current date of the week of js system for your reference. The specific contents are as follows

Method 1:


//  What day of the week is the computing system currently 
var str = " Today is a week " + " Day 123456".charat(new date().getday());

Method 2:


var a = new array(" Day ", "1", "2", "3", "4", "5", "6");
var week = new date().getday();
var str = " Today is a week "+ a[week];
alert(str);

Method 3:


var str = " Today is a week ";
var week = new date().getday();
switch (week) {
  case 0 :
    str1 += " Day ";
    break;
  case 1 :
    str1 += "1";
    break;
  case 2 :
    str1 += "2";
    break;
  case 3 :
    str1 += "3";
    break;
  case 4 :
    str1 += "4";
    break;
  case 5 :
    str1 += "5";
    break;
  case 6 :
    str1 += "6";
    break;
}
alert(str);

Method 4:


var str = "";
var week = new date().getday();
if (week == 0) {
  str = " Today is Sunday ";
} else if (week == 1) {
  str = " Today is a week 1";
} else if (week == 2) {
  str = " Today is a week 2";
} else if (week == 3) {
  str = " Today is a week 3";
} else if (week == 4) {
  str = " Today is a week 4";
} else if (week == 5) {
  str = " Today is a week 5";
} else if (week == 6) {
  str = " Today is a week 6";
}
alert(str);

Related articles: