Hello
I want to make a calendar, but I don't know how to calculate the number of days in month, in any year.
How can I get the number of days in any month in a year, taking into account leap years?
Get number of days in month in JavaScript
-
- Posts:107
Get number of days in month in JavaScript
Admin
Posts:805
Hello
You can use the daysInMonth() function from this example (month is 1 based):
- If someone needs, in PHP there is the cal_days_in_month() function.
You can use the daysInMonth() function from this example (month is 1 based):
Code: Select all
//Returns the number of days in a given month (1 - 12) and year
function daysInMonth(month, year){
return month == 2 ? (year %4 ? 28 : (year %100 ? 29 : (year %400 ? 28 :29))) : ((month -1) %7% 2 ? 30 :31);
}
var nr_days = daysInMonth(2, 2016);
alert(nr_days); // 29
Code: Select all
$nr_days = cal_days_in_month(CAL_GREGORIAN, 8, 2003); // 31
Similar Topics
- Display message to every minute in Javascript
JavaScript - jQuery - Ajax First post
Hello,Last post
On eatch minute from the current hour I wanna have an message
I can not find out how to complete
I hope to get something like this (code...
If you only want to display a message to every minute, just use the setInterval() function. It calls a function repeatedly, over and over again, at... - Hour and Minutes togheter in Javascript
JavaScript - jQuery - Ajax First post
Dear Coursesweb I can not find out how to add the hours + minutes togheter.Last post
<SCRIPT LANGUAGE= JavaScript >
day = new Date()
hr =...
See and use the following example:
<script>
var day = new Date();
let hr = day.getHours();
let mn = day.getMinutes();
let se =...