function getCurrentDate(){
var today = new Date();
var day = today.getDate();
var month = today.getMonth() + 1;
var year = today.getYear();
if(year<1900) year += 1900;
//The value returned by getYear is the year less 1900. For example,
//if the year is 1976, the value returned is 76.
hour = today.getHours();
minute = today.getMinutes();
second = today.getSeconds();
day=day-1;
if(day==0)
{
month=month-1;
day=getMaxDay(year,month)
}
if(day<10) day = '0'+day;
if(month<10) month = '0'+month;
return year+"-"+month+"-"+day
}
/**
* 用途:获取每月的最后一天日期值.
* 输入:date:年份;month:月份
* 返回:如果通过验证返回true,否则返回false
*/
function getMaxDay(year,month) {
if(month==04||month==06||month==09||month==11)
return "30";
if(month==02)
if(year%4==0&&year%100!=0 || year%400==0)
return "29";
else
return year+"-"+month+"-"+"28";
return "31";
}
==========================================================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<SCRIPT LANGUAGE="JavaScript">
function getCurrentDate(){
var today = new Date();
var day = today.getDate();
var month = today.getMonth() + 1;
var year = today.getYear();
if(year<1900) year += 1900;
//The value returned by getYear is the year less 1900. For example,
//if the year is 1976, the value returned is 76.
hour = today.getHours();
minute = today.getMinutes();
second = today.getSeconds();
day=day-1;
if(day==0)
{
month=month-1;
day=getMaxDay(year,month)
}
if(day<10) day = '0'+day;
if(month<10) month = '0'+month;
return year+"-"+month+"-"+day
}
</SCRIPT>
</HEAD>
<BODY>
<button value="当前日期" onclick="alert(getCurrentDate())">currentDate</button>
</BODY>
</HTML>