get days of month javascript code example
Example 1: how to get the number of days in a month in javascript
// instantiate a date object
var dt = new Date();
// dt.getMonth() will return a month between 0 - 11
// we add one to get to the last day of the month
// so that when getDate() is called it will return the last day of the month
var month = dt.getMonth() + 1;
var year = dt.getFullYear();
// this line does the magic (in collab with the lines above)
var daysInMonth = new Date(year, month, 0).getDate();
Example 2: js get date day month year
var dateObj = new Date();
var month = dateObj.getUTCMonth() + 1; //months from 1-12
var day = dateObj.getUTCDate();
var year = dateObj.getUTCFullYear();
newdate = year + "/" + month + "/" + day;
Example 3: daysinmonth javascript
var dt = new Date();
var month = dt.getMonth();
var year = dt.getFullYear();
daysInMonth = new Date(year, month, 0).getDate();
Example 4: js get day month year
const d = new Date();
d.getMonth() + 1; // Month [mm] (1 - 12)
d.getDate(); // Day [dd] (1 - 31)
d.getFullYear(); // Year [yyyy]