Javascript calculates the remaining days of the month calculator sample code

  • 2020-03-30 01:17:08
  • OfStack

The code is as follows:


<script language="JavaScript">
<!-- Begin
var today = new Date();
var now = today.getDate();
var year = today.getYear();
if (year < 2000) year += 1900; // Y2K fix
var month = today.getMonth();
var monarr = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
// check for leap year
if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) monarr[1] = "29";
// display day left
document.write(" There's still a month left  " + (monarr[month]-now) + "  days ");
//  End -->
</script>


Related articles: