如何在javascript中获取从日期算起的月份?
我正在尝试从日期变量中获取月份如何在javascript中获取从日期算起的月份?,javascript,Javascript,我正在尝试从日期变量中获取月份 date=Date.now(); console.log(date); >>2019-12-04T08:55:48.972Z 我想获取从该日期开始的月份,但当我使用getMonth()时,会出现错误 console.log(date.getMonth()); error:- getMonth is not a function 你可以试试这个 let date= new Date(); console.log(date.getMonth())
date=Date.now();
console.log(date);
>>2019-12-04T08:55:48.972Z
我想获取从该日期开始的月份,但当我使用getMonth()时,会出现错误
console.log(date.getMonth());
error:- getMonth is not a function
你可以试试这个
let date= new Date();
console.log(date.getMonth());
你需要这个日期对象 试试这个:
let date=新日期();
console.log(date.getMonth()+1)
尝试删除。现在
。
应该是date=newdate()代码>参见var d=new Date();var n=d.getMonth()
Date.now()
返回一个数字,我很惊讶您在第一个代码块中得到一个字符串结果
let date= new Date('2019-10-04T08:55:48.972Z');
console.log(date.getMonth()+1);