Date.getDay()javascript返回错误的一天 [英] Date.getDay() javascript returns wrong day

查看:121
本文介绍了Date.getDay()javascript返回错误的一天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新的javascript
我有这样的JavaScript代码

  alert(DATE.value); 
var d = new Date(DATE.value);
var year = d.getFullYear();
var month = d.getMonth();
var day = d.getDay();
alert(月);
alert(day);
if(2012< year< 1971 | 1>月+ 1> 12 | 0>天> 31){
alert(errorDate)
DATE.focus();
返回false;
}

DATE.value =11/11/1991

$当我打电话(day)时,b
$ b

它显示我3;

当我打电话alert(d);它将返回正确的信息

解决方案

使用 .getDate 而不是 .getDay


getDay返回的值是一个对应于周:周日为0,星期一为1,星期二为2,等等。



Hi I'm new in javascript I have such javascript code

    alert(DATE.value);
    var d = new Date(DATE.value);
    var year = d.getFullYear();
    var month = d.getMonth();
    var day = d.getDay();
    alert(month);
    alert(day);
    if(2012 < year < 1971 | 1 > month+1 > 12 | 0 >day > 31){
        alert(errorDate);
        DATE.focus();
        return false;
    }

DATE.value = "11/11/1991"

when I call alert(day); it shows me 3;
when I call alert(d); it is returns me correct info

解决方案

use .getDate instead of .getDay.

The value returned by getDay is an integer corresponding to the day of the week: 0 for Sunday, 1 for Monday, 2 for Tuesday, and so on.

这篇关于Date.getDay()javascript返回错误的一天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆