如何在javascript中获取当月的日期?

时间:2022-10-16 08:53:58

I need to get the day of the month from a Date object but it seems that the getDay() method returns the day of the week. Is there a function that returns the day of the month?

我需要从Date对象获取月中的某一天,但似乎getDay()方法返回星期几。是否有返回当月日期的函数?

4 个解决方案

#1


46  

Use date_object.getDate() to get the month day.

使用date_object.getDate()获取月份日。

From the MDN docs link:

从MDN文档链接:

"Returns the day of the month for the specified date according to local time."

“根据当地时间返回指定日期的月份日期。”

#2


14  

Try getDate() instead. Confusing naming, but that's life...

请尝试使用getDate()。令人困惑的命名,但这就是生活......

#3


8  

var date = new Date().getDate();

#4


2  

.getDate() 

is the method you want to call on a date object. As show in the documentation:

是您要在日期对象上调用的方法。如文档中所示:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date

#1


46  

Use date_object.getDate() to get the month day.

使用date_object.getDate()获取月份日。

From the MDN docs link:

从MDN文档链接:

"Returns the day of the month for the specified date according to local time."

“根据当地时间返回指定日期的月份日期。”

#2


14  

Try getDate() instead. Confusing naming, but that's life...

请尝试使用getDate()。令人困惑的命名,但这就是生活......

#3


8  

var date = new Date().getDate();

#4


2  

.getDate() 

is the method you want to call on a date object. As show in the documentation:

是您要在日期对象上调用的方法。如文档中所示:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date