getmonth函数,date getmonth

getmonth

JavaScript Date getMonth()方法 (JavaScript Date getMonth() method)

getMonth() method is a Date’s class method and it is used to get the value of the month from the current date.

getMonth()方法是Date的类方法,用于从当前日期获取月份的值。

It accepts nothing as the parameter and returns a value between 0 to 11.

它不接受任何内容作为参数,并返回0到11之间的值。

Note: Returned value is from 0 to 11, 0 for January, 1 for February, …, 11 for December

注意:返回值是从0到11,一月为0,二月为1,…,十二月为11

Syntax:

句法:

var dt = new Date(); dt.getMonth();

Examples:

例子:

Input: var dt = new Date(); dt.getMonth(); Output: 2 (if current month is March)

JavaScript code to get the month value from the current date using getMonth() method

JavaScript代码使用getMonth()方法从当前日期获取月份值

<html><head><title>JavaScipt Example</title></head><body><script>var dt = new Date(); //Date constructor var month = dt.getMonth(); //getting month from the current date//printing monthdocument.write(“Current month is : ” + month);</script></body></html>

Output

输出量

Current month is : 2

翻译自: https://www.includehelp.com/code-snippets/date-getMonth-method-with-example-in-javascript.aspx

getmonth

Published by

风君子

独自遨游何稽首 揭天掀地慰生平

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注