简体   繁体   English

获取当月的第一天名字(星期一,星期二…)

[英]Get the first day name (Mon, Tues…) of the month

As the title says I'm trying to get the first day name that a given month starts on. 如标题所示,我正在尝试获取给定月份开始的第一天的名字。 So for example if Oct 2014 was given the code would return 3 because there are 3 empty blocks before Wed the 1st. 因此,例如,如果给出了2014年10月的代码,则该代码将返回3,因为在第1周三之前有3个空块。 Again if I provided Jan 2015, I should get 4. Here is my function: 同样,如果我提供2015年1月的信息,我应该得到4。这是我的函数:

function getDayMonthStartsOn(month, year) {
    var day = new Date(year + "-" + month + "-01").getDay();
    day = (day === 0) ? 7 : day;
    return day;
}

My problem is that it seems to work for Jan 2015 but not Oct 2014. 我的问题是,它似乎适用于2015年1月,但不适用于2014年10月。

使用getUTCDay()而不是getDay()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM