Share via


getMonth 方法

更新:2007 年 11 月

利用本地時間傳回 Date 物件中的月份值。

 function getMonth() : Number

備註

若要利用 Coordinated Universal Time (UTC) 取得月份值,請使用 getUTCMonth 方法。

getMonth 方法會傳回一個介於 0 到 11 之間的整數,代表 Date 物件中的月份值。傳回的整數並非人們慣用來表示月份的數字。而是比實際月份少一的數字。如果 Date 物件中儲存 "Jan 5, 1996 08:47:00" 的話,getMonth 會傳回 0。

範例

以下範例說明如何使用 getMonth 方法。

function DateDemo(){
   var d, s = "Today's date is: ";
   d = new Date();
   s += (d.getMonth() + 1) + "/";
   s += d.getDate() + "/";
   s += d.getYear();
   return(s);
}

需求

1 版

套用至︰

Date 物件

請參閱

參考

getUTCMonth 方法

setMonth 方法

setUTCMonth 方法