getMonth函數用于獲取日期對象中的月份部分,返回值是一個介于0和11之間的整數,分別代表1月到12月。getMonth函數的正確用法是:
var date = new Date(); var month = date.getMonth(); console.log(month); // 返回當前月份的數字(0-11)