Hướng dẫn getmonth in javascript - getmonth trong javascript

Examples

Get the month:

const d = new Date(); let month = d.getMonth();
let month = d.getMonth();

Try it Yourself »

Get the name of the month (not just a number):

const month = ["January","February","March","April","May","June","July","August","September","October","November","December"];

const d = new Date(); let name = month[d.getMonth()];
let name = month[d.getMonth()];

Try it Yourself »


Get the name of the month (not just a number):

const month = ["January","February","March","April","May","June","July","August","September","October","November","December"];

const d = new Date(); let name = month[d.getMonth()];


Definition and Usage

getMonth() returns the month (0 to 11) of a date.

January =0, February = 1, ... (see below):

SyntaxParameters
Return ValueType


Description

A number

The month of the date (0 to 11).

Browser SupportgetMonth() is an ECMAScript1 (ES1) feature.ES1 (JavaScript 1997) is fully supported in all browsers:Chrome IE Edge
Firefox Firefox Firefox Firefox Firefox Firefox



Miêu tả

Phương thức date getMonth() trong Javascript trả về tháng của ngày đã cho theo Local time. Giá trị được trả về bởi getMonth() là một số integer giữa 0 và 11. 0 tương ứng với January, 1 với February, và tiếp tục.getMonth() trong Javascript trả về tháng của ngày đã cho theo Local time. Giá trị được trả về bởi getMonth() là một số integer giữa 0 và 11. 0 tương ứng với January, 1 với February, và tiếp tục.

Cú pháp

Cú pháp của nó như sau:

Date.getMonth()

Trả về giá trị:

Trả về tháng của ngày đã cho theo Local time.

Ví dụ

Bạn thử ví dụ sau:


   
      JavaScript getMonth Method
   
   
   
   
      
      
   

Quảng cáo

Kết quả

getMonth() : 11 

Đã có app VietJack trên điện thoại, giải bài tập SGK, SBT Soạn văn, Văn mẫu, Thi online, Bài giảng....miễn phí. Tải ngay ứng dụng trên Android và iOS.

Hướng dẫn getmonth in javascript - getmonth trong javascript

Hướng dẫn getmonth in javascript - getmonth trong javascript

Theo dõi chúng tôi miễn phí trên mạng xã hội facebook và youtube:

Các bạn có thể mua thêm khóa học JAVA CORE ONLINE VÀ ỨNG DỤNG cực hay, giúp các bạn vượt qua các dự án trên trường và đi thực tập Java. Khóa học có giá chỉ 300K, nhằm ưu đãi, tạo điều kiện cho sinh viên cho thể mua khóa học.

Nội dung khóa học gồm 16 chuơng và 100 video cực hay, học trực tiếp tại https://www.udemy.com/tu-tin-di-lam-voi-kien-thuc-ve-java-core-toan-tap/ Bạn nào có nhu cầu mua, inbox trực tiếp a Tuyền, cựu sinh viên Bách Khoa K53, fb: https://www.facebook.com/tuyen.vietjack

Follow facebook cá nhân Nguyễn Thanh Tuyền https://www.facebook.com/tuyen.vietjack để tiếp tục theo dõi các loạt bài mới nhất về Java,C,C++,Javascript,HTML,Python,Database,Mobile.... mới nhất của chúng tôi.

Các bài học JavaScript khác tại VietJack::

  • Javascript - Cú pháp
  • Javascript - Kích hoạt
  • Javascript - Vị trí trong HTML File
  • Javascript - Biến
  • Javascript - Toán tử
  • Javascript - Lệnh If...Else

doi_tuong_date_trong_javascript.jsp



Bài viết liên quan

  • 160 bài học ngữ pháp tiếng Anh hay nhất

  • 155 bài học Java tiếng Việt hay nhất

  • 100 bài học Android tiếng Việt hay nhất

  • 247 bài học CSS tiếng Việt hay nhất

  • 197 thẻ HTML cơ bản

  • 297 bài học PHP

  • 101 bài học C++ hay nhất

  • 97 bài tập C++ có giải hay nhất

  • 208 bài học Javascript có giải hay nhất

The getMonth() method returns the month in the specified date according to local time, as a zero-based value (where zero indicates the first month of the year). getMonth() method returns the month in the specified date according to local time, as a zero-based value (where zero indicates the first month of the year).

Try it

Syntax

Return value

An integer number, between 0 and 11, representing the month in the given date according to local time. 0 corresponds to January, 1 to February, and so on.

Examples

Using getMonth()

The second statement below assigns the value 11 to the variable month, based on the value of the Date object


   
      JavaScript getMonth Method
   
   
   
   
      
      
   

0.

const xmas95 = new Date('December 25, 1995 23:15:30');
const month = xmas95.getMonth();

console.log(month); // 11

Note: If needed, the full name of a month (


   
      JavaScript getMonth Method
   
   
   
   
      
      
   

1 for example) can be obtained by using

   
      JavaScript getMonth Method
   
   
   
   
      
      
   

2 with an

   
      JavaScript getMonth Method
   
   
   
   
      
      
   

3 parameter. Using this method, internationalization is made easier:
If needed, the full name of a month (

   
      JavaScript getMonth Method
   
   
   
   
      
      
   

1 for example) can be obtained by using

   
      JavaScript getMonth Method
   
   
   
   
      
      
   

2 with an

   
      JavaScript getMonth Method
   
   
   
   
      
      
   

3 parameter. Using this method, internationalization is made easier:

const options = { month: 'long'};
console.log(new Intl.DateTimeFormat('en-US', options).format(Xmas95));
// December
console.log(new Intl.DateTimeFormat('de-DE', options).format(Xmas95));
// Dezember

Thông số kỹ thuật

Sự chỉ rõ
Đặc tả ngôn ngữ Ecmascript # sec-date.prototype.getmonth
# sec-date.prototype.getmonth

Tính tương thích của trình duyệt web

Bảng BCD chỉ tải trong trình duyệt

Xem thêm