| ● setMonth メソッド
 
 
 
| 【機能】 | Dateオブジェクトの 月 をセットします。※ 月は、0 (1 月) 〜 11 (12 月) です。 |  | 【書式】 | objDate.setMonth( numMonth[, dateVal] ) |  
| 【 例 】 | objDate = new Date(); objDate.setMonth( -1 ); // 12月へ変更
 y = objDate.getFullYear();
 M = objDate.getMonth() + 1;
 d = objDate.getDate();
 h = objDate.getHours();
 m = objDate.getMinutes();
 s = objDate.getSeconds();
 f = objDate.getMilliseconds();
 document.write(y,"/",M,"/",d," ",h,":",m,":",s,".",f);
 |  |  | 【 例 】 | objDate = new Date( 2013, 4, 30 ); // 2013/5/30をセット objDate.setMonth( 3 ); // 4月へ変更
 y = objDate.getFullYear();
 M = objDate.getMonth() + 1;
 d = objDate.getDate();
 h = objDate.getHours();
 m = objDate.getMinutes();
 s = objDate.getSeconds();
 f = objDate.getMilliseconds();
 document.write(y,"/",M,"/",d," ",h,":",m,":",s,".",f);
 |  |  | 【 例 】 | objDate = new Date( 2013, 4, 31 ); // 2013/5/31をセット objDate.setMonth( 3 ); // 4月へ変更
 y = objDate.getFullYear();
 M = objDate.getMonth() + 1;
 d = objDate.getDate();
 h = objDate.getHours();
 m = objDate.getMinutes();
 s = objDate.getSeconds();
 f = objDate.getMilliseconds();
 document.write(y,"/",M,"/",d," ",h,":",m,":",s,".",f);
 |  |  ※ 月の値は 0月 〜 11月でセットします。
 ※ numMonth に 0 〜 11 以外の値のセットした場合、例えば、-1 を指定した場合は、去年の12月になります。
 ※ 5/31 の時に 4月へ変更した場合は 4月は30日までしかないので、4/31 → 5/1 になります。
 
 |