How do I get the day of the month in javascript?

2020-06-06 08:09发布

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?

标签: javascript
5条回答
放我归山
2楼-- · 2020-06-06 08:33

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

From the MDN docs link:

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

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2020-06-06 08:38

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

查看更多
ら.Afraid
4楼-- · 2020-06-06 08:41
var date = new Date().getDate();
查看更多
Lonely孤独者°
5楼-- · 2020-06-06 08:41
.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

查看更多
家丑人穷心不美
6楼-- · 2020-06-06 08:42
const date = new Date();

const day = date.getDate();
const month = date.getMonth() + 1;
const year = date.getFullYear();
查看更多
登录 后发表回答