我是javascript的新手,我有这个日期值(出生= 1986-12-14),我想把它改成字符串,但我得到的只是减法操作。
var birth = 1986-12-14;
console.log(birth.toString());
output: 1960
我希望结果是“1986-12-14”
var birth = 1986-12-14;
制作birth = 1960
,因为1986-12-14
不是约会,它是一个数学表达式。
如果你想要约会,请使用date。
注意:月份表示为从
0
开始的整数。所以,如果你想要12月,你可以使用11
这个月。
var birth = new Date(1986,11,14);
// Extract the parts of the date that you want and build a string from them.
// Adjust the month for human consumption
console.log(birth.getFullYear() + "-" + (birth.getMonth() + 1) + "-" + birth.getDate());