var d=new Date();
var thisYear=d.getFullYear();
var thisMonth=d.getMonth();
if(thisMonth==0)
{
    thisYear=thisYear-1;
    thisMonth=12;
}
else
    thisMonth=thisMonth-1;

var allMonth=[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
var allMonth2=[31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

//判断是否为润年
if(thisYear%400==0 || (thisYear%4==0 && thisYear%100!=0))
    thisDay=allMonth2[thisMonth-1];
else
    thisDay=allMonth[thisMonth-1];

 var date1=thisYear+"/"+thisMonth+"/"+"1"; //月头
 var date2=thisYear+"/"+thisMonth+"/"+thisDay; //月尾

解决方案 »

  1.   

    <script>
    function _getDate(newdate){
       var d, s;                  // 声明变量。
       d = new Date();            // 创建 date 对象。
       d.setDate(newdate);        // 设置 date 为 newdate。   return d;
                  
    }
    function _getDate1(odate){
    odate.setDate(1)
    return odate;}
    function shortName(oDate)
    {
        var s=oDate.getYear()+"年";

    s+=oDate.getMonth()+"月";

    s+=oDate.getDate()+"日 ";

    s+=_getDay(oDate);
    return s;
    }
    alert("上月月初日期:"+shortName(_getDate1(_getDate(0))));
    alert("上月月尾日期:"+shortName(_getDate(0)));
    function _getDay(oDate){   var i=oDate.getDay();
       switch (i)
       {
       case 0: return "星期日"
       case 1: return "星期一"
       case 2: return "星期二"
       case 3: return "星期三"
       case 4: return "星期四"
       case 5: return "星期五"
       case 6: return "星期六"
    default :return false;
    }}</script>
      

  2.   

    不好意思我写错了。。s+=(oDate.getMonth()+1)+"月";这样就好了:)