到目前为止,我只知道如何获取当前年份:
const date = new Date()
const year = date.getFullYear()
=> 2017 <- find how many months have passed in this year relative with the current date
我在谷歌上搜索,我能找到的最接近的东西是同样的问题,但在PHP中。
(例如,今年只有1
月,因为我们在一月份。
输出:
如果你今天运行代码,你会得到这个 02 年 1 月:
{ months: 1 }
查找今年相对于过去了多少个月 当前日期
就做date.getMonths
var monthsElapsed = date.getMonth() + 1;