📅  最后修改于: 2023-12-03 15:01:37.627000             🧑  作者: Mango
Javascript has a built-in date object that represents a date and time. The getDate() method allows you to get the day of the month (from 1 to 31) of a date object.
date.getDate()
none
The getDate() method returns the day of the month (from 1 to 31) for the specified date according to local time.
const today = new Date();
const dayOfMonth = today.getDate();
console.log(dayOfMonth);
Output:
17
In the example above, a new date object (today
) is created using the Date()
constructor. The getDate()
method is then called on the today
object to get the day of the month. This value is then printed to the console using console.log()
. Since today's date is August 17th (at the time of writing), the value returned by getDate()
is 17
.
The getDate() method is a useful tool for getting the day of the month from a date object in Javascript. With the information returned by this method, you can perform a wide range of date and time calculations in your code.