Date.prototype.getMonth()
Baseline
åºãå©ç¨å¯è½
ãã®æ©è½ã¯åºãå®è£ ããã¦ãããå¤ãã®ãã¼ã¸ã§ã³ã®ç«¯æ«ããã©ã¦ã¶ã¼ã§åä½ãã¾ãã2015å¹´7æä»¥éããã¹ã¦ã®ãã©ã¦ã¶ã¼ã§å©ç¨å¯è½ã§ãã
getMonth() 㯠Date ã¤ã³ã¹ã¿ã³ã¹ã®ã¡ã½ããã§ããã®æ¥ä»ã®ãæãã表ã 0 ãåºç¹ã¨ããå¤ï¼ããªãã¡ 0 ãå¹´ã®æåã®æã示ãï¼ãè¿ãã¾ãã
試ãã¦ã¿ã¾ããã
const moonLanding = new Date("July 20, 69 00:20:18");
console.log(moonLanding.getMonth()); // (January gives 0)
// äºæ³ãããçµæ: 6
æ§æ
getMonth()
弿°
ãªãã
è¿å¤
å°æ¹æã«åºã¥ããæå®ãããæ¥æã®ãæãã表ã 0 ãã 11 ã¾ã§ã®éã®æ´æ°å¤ã§ãã 1 æã¯ 0ã2 æ 㯠1 ã¨ããããã«ãªãã¾ããæ¥æãç¡å¹ãªå ´å㯠NaN ãè¿ãã¾ãã
解説
getMonth() ã®è¿å¤ã¯ 0 ããå§ã¾ããããä¾ãã°ãæã®é
åã®ã¤ã³ããã¯ã¹æå®ã«æçã§ãã
const valentines = new Date("1995-02-14");
const month = valentines.getMonth();
const monthNames = ["January", "February", "March" /* , ⦠*/];
console.log(monthNames[month]); // "February"
ãã ããå½éåã®ããã«ã¯ã代ããã« Intl.DateTimeFormat ã options 弿°ä»ãã§ä½¿ç¨ãããã¨ããå§ããã¾ãã
const options = { month: "long" };
console.log(new Intl.DateTimeFormat("en-US", options).format(valentines));
// "February"
console.log(new Intl.DateTimeFormat("de-DE", options).format(valentines));
// "Februar"
ä¾
>getMonth() ã®ä½¿ç¨
夿° month ã«ã¯ã Date ãªãã¸ã§ã¯ã xmas95 ã«åºã¥ãã¦ã 11 ã¨ããå¤ãå
¥ãã¾ãã
const xmas95 = new Date("1995-12-25T23:15:30");
const month = xmas95.getMonth();
console.log(month); // 11
仿§æ¸
| 仿§æ¸ |
|---|
| ECMAScript® 2027 Language Specification > # sec-date.prototype.getmonth > |