A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.cdn.mozilla.net/ko/docs/Web/JavaScript/Reference/Global_Objects/Date/getMonth below:

Date.prototype.getMonth() - JavaScript | MDN

Date.prototype.getMonth()

Baseline Widely available

getMonth() 메서드는 Date 객체의 월 값을 현지 시간에 맞춰 반환합니다. 월은 0부터 시작합니다.

시도해 보기
const moonLanding = new Date("July 20, 69 00:20:18");

console.log(moonLanding.getMonth()); // (January gives 0)
// Expected output: 6
구문 반환 값

현지 시간 기준 월을 나타내는 0에서 11 사이의 정수. 0은 1월, 1은 2월... 을 나타냅니다.

예제 getMonth() 사용하기

다음 예제는 Date 객체 Xmas95의 값을 사용해 변수 month에 11을 할당합니다.

var Xmas95 = new Date("December 25, 1995 23:15:30");
var month = Xmas95.getMonth();

console.log(month); // 11

참고: 참고: 필요한 경우 Intl.DateTimeFormat()과 options 매개변수를 사용해 해당하는 달의 이름("January" 등)을 가져올 수 있습니다. 이 방법을 사용하면 국제화도 보다 편리합니다.

var options = { month: "long" };
console.log(new Intl.DateTimeFormat("ko-KR", options).format(Xmas95));
// 12월
console.log(new Intl.DateTimeFormat("en-US", options).format(Xmas95));
// December
명세 브라우저 호환성 같이 보기

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4