javascript get day of week code example
Example 1: get day js
switch (new Date().getDay()) {
case 0:
day = "Sunday";
break;
case 1:
day = "Monday";
break;
case 2:
day = "Tuesday";
break;
case 3:
day = "Wednesday";
break;
case 4:
day = "Thursday";
break;
case 5:
day = "Friday";
break;
case 6:
day = "Saturday";
}
Example 2: javascript date get day of week abbreviation
var days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
var d = new Date(dateString);
var dayName = days[d.getDay()];
Example 3: javascript get date of the week
let date = new Date();
let dayOfWeekNumber = date.getDay();
let nameOfDay;
let quote;
switch(dayOfWeekNumber){
case 0:
nameOfDay = 'Sunday';
quote = 'Time to chillax!';
break;
case 1:
nameOfDay = 'Monday';
quote = 'Monday morning blues!';
break;
case 2:
nameOfDay = 'Tuesday';
quote = 'Taco Time!';
break;
case 3:
nameOfDay = 'Wednesday';
quote = 'Two more days to the weekend.';
break;
case 4:
nameOfDay = 'Thursday';
quote = 'The weekend is almost here...';
break;
case 5:
nameOfDay = 'Friday';
quote = 'Weekend is here!';
break;
case 6:
nameOfDay = 'Saturday';
quote = 'Time to party!';
break;
}
let weekdayDiv = document.getElementById('weekday');
weekdayDiv.innerHTML = `${nameOfDay}`;
let quoteDiv = document.getElementById('phrase');
quoteDiv.innerHTML = `${quote}`
Example 4: javascript get day
var d = new Date();
var n = d.getDay();
Example 5: get date one week from now javascript
function nextweek(){
var today = new Date();
var nextweek = new Date(today.getFullYear(), today.getMonth(), today.getDate()+7);
return nextweek;
}
Example 6: new date getday js
Date.getDay()