Javascript 如何获取当前年份已过去的月数(相对于当前日期)?
到目前为止,我只知道如何获得本年度:Javascript 如何获取当前年份已过去的月数(相对于当前日期)?,javascript,Javascript,到目前为止,我只知道如何获得本年度: const date = new Date() const year = date.getFullYear() => 2017 <- find how many months have passed in this year relative with the current date 找出今年相对于 当前日期 只需执行date.getMonths var monthsElapsed = date.getMonth() + 1; 请分享更多
const date = new Date()
const year = date.getFullYear()
=> 2017 <- find how many months have passed in this year relative with the current date
找出今年相对于
当前日期
只需执行date.getMonths
var monthsElapsed = date.getMonth() + 1;
请分享更多的输入和输出示例。您尝试和研究了哪些内容?一般来说,询问没有预期输出的代码也是如此,而不是在没有亲自尝试任何代码的情况下提问。@gurvinder372没有输入。只是我提供的代码。(我添加了一些输出)。你能不能只做
date.getMonth()+1
?但2018年:P
var monthsElapsed = date.getMonth() + 1;