---
title: "javascript取当月最后一天"
author: "ctrain"
date: "2012-12-14T19:07:56Z"
tags: []
categories: ["Web前端"]
slug: "javascript"
draft: false
lastmod: "2012-12-14T19:07:56Z"
id: 1748215
url: "https://ctrain.iteye.com/blog/1748215"
---

```javascript

<!--javascript取当月最后一天-->
<script   language=javascript>  
  var current = new Date();
  var year = current.getYear();
  var month = current.getMonth();
  showMonthLastDay(year, month);
 
  function   showMonthLastDay(year,month)   
  { 
	alert("year:"+year+", month:"+month);
	year = ( year < 1900 ) ? ( 1900 +year ) : year;
	var tempDate = new Date();
	tempDate.setYear(year);
	tempDate.setMonth(month+1);
	tempDate.setDate(0);
	var tempYear = tempDate.getYear();
	tempYear = ( tempYear < 1900 ) ? ( 1900 +tempYear ) : tempYear;

	alert("本月最后一天："+tempYear+"-"+(tempDate.getMonth()+1)+"-"+tempDate.getDate());  
  }   
</script>

```