给你一个日期,请你设计一个算法来判断它是对应一周中的哪一天。
输入为三个整数:day、month 和 year,分别表示日、月、年。
您返回的结果必须是这几个值中的一个 {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}。
示例 1:
输入:day = 31, month = 8, year = 2019 输出:"Saturday"
调用 Date 函数,不墨迹
var dayOfTheWeek = function (day, month, year) {
let date = new Date();
date.setFullYear(year, month - 1, day);
let ans = [
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
];
return ans[date.getDay()];
};