我需要从 Date 对象获取月份的日期,但似乎 getDay()方法返回星期的日期。是否有一个函数返回月中的某一天?
getDay()
Use date_object.getDate() to get the month day.
date_object
.getDate()
From the MDN docs link:
"Returns the day of the month for the specified date according to local time."
Try getDate() instead. Confusing naming, but that's life...
var date = new Date().getDate();
From Mozilla Developer Network:
Date.prototype.getDate() The getDate() method returns the day of the month for the specified date according to local time.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getDate
const date = new Date(); const day = date.getDate(); const month = date.getMonth() + 1; const year = date.getFullYear();