Date 객체는 JavaScript 언어에 내장된 데이터 유형입니다. Date 객체는 아래와 같이 새로운 Date( )로 생성됩니다.
Date 개체가 생성되면 여러 메서드를 사용하여 해당 개체에 대해 작업할 수 있습니다. 대부분의 방법을 사용하면 로컬 시간이나 UTC(범용 또는 GMT) 시간을 사용하여 개체의 연도, 월, 일, 시, 분, 초 및 밀리초 필드를 가져오고 설정할 수 있습니다.
getUTCMonth() Date 개체의 함수는 세계시(0은 1월을 나타냄 등...)에 따라 주어진 날짜의 월을 반환합니다.
구문
구문은 다음과 같습니다.
dateObj.getUTCMonth();
예시
<html>
<head>
<title>JavaScript Example</title>
</head>
<body>
<script type="text/javascript">
var dateObj = new Date('September 26, 1989 12:4:25:96');
document.write(dateObj.getUTCMonth());
</script>
</body>
</html> 출력
8
예시
날짜 객체를 생성할 때 월을 언급하지 않은 경우 이 함수는 세계시를 기준으로 0을 반환합니다.
<html>
<head>
<title>JavaScript Example</title>
</head>
<body>
<script type="text/javascript">
var dateObj = new Date('1989 12:4:25:96');
document.write(dateObj.getUTCMonth());
</script>
</body>
</html> 출력
0
예시
같은 방법으로 날짜 객체를 생성하는 동안 아무 것도 전달하지 않았다면 이 함수는 세계시를 기준으로 현재 연도의 현재 월을 반환합니다.
<html>
<head>
<title>JavaScript Example</title>
</head>
<body>
<script type="text/javascript">
var dateObj = new Date();
document.write("Month of the year:+ "dateObj.getUTCMonth());
</script>
</body>
</html> 출력
Month of the year: 9