new Date()函数返回错误的值

时间:2017-05-12 07:20:50

标签: javascript

新日期(代码)返回工作值,请帮帮我

var cdt = new Date();

dob = "15/01/1999";//From date picker
alert(dob);

    var bdy = dob.split("/");
    var by = bdy[2];
    var bm = bdy[0];
    var bd = bdy[1];

    var dob = new Date(bd, bm, by);
alert(bd+","+bm+","+by);
alert(dob);

新日期()函数的日期格式已更改:

enter image description here

该函数返回值:

enter image description here

1 个答案:

答案 0 :(得分:1)

new Date()方法在构造函数上有三个参数。

参数的顺序如下:yearmonthday

像这样:var date=new Date(1999,01,01)

var cdt = new Date();
dob = "15/01/1999";//From date picker

var bdy = dob.split("/");
var by = bdy[2];
var bm = bdy[1];
var bd = bdy[0];
var dob = new Date(by, (bm-1), bd);
console.log(bd+","+bm+","+by);
console.log(dob.toLocaleDateString());