<script> 
  //取得明年的今天 
  function getNextYear(){ 
    var today = new Date(); 
    var y,m,d; 
    d = today.getDate(); 
    m = today.getMonth() + 1;//月是从0开始 
    y = today.getYear(); 
    y++;//年加1 
    if(m==2 && d==29) 
      return new Date(y,3,1);//如果是闰年,返回3月1日 
    else 
      return new Date(y,m,d);//如果是闰年,返回3月1日 
  } 
  
  //取得下个月的今天 
  function getNextMonth(){ 
    var today = new Date(); 
    var y,m,d; 
    d = today.getDate(); 
    m = today.getMonth() + 1;//月是从0开始 
    y = today.getYear(); 
    
    m++; 
    if( m > 12){//月份加1,如果大于12,则月份为1份,年份加1 
      m=1;y++; 
    } 
  
    if( !checkDate(y + '-' + m + '-' + d) ){//如果不是日期,那么月份加1,日等于1 
      m++; 
      if( m > 12){//月份加1,如果大于12,则月份为1份,年份加1 
        m=1;y++; 
      } 
      d=1; 
    } 
    var nextToday = new Date(y, m, d); 
    return nextToday; 
  } 
  
  //判断是否正确的日期,格式:年-月-日 
  function checkDate(str) 
  { 
      var tmp = new Date(str); 
      var y = tmp.getFullYear(); 
      var m = tmp.getMonth()+1; 
      var d = tmp.getDate(); 
      var nday = y + "-" + m + "-" + d 
      if (nday != str) 
        return false; 
      else 
        return true; 
  } </script>
参考下就可以了,刚刚不是问过的吗?

解决方案 »

  1.   

    // 日期格式化   
    // 格式 YYYY/yyyy/YY/yy 表示年份   
    // MM/M 月份   
    // W/w 星期   
    // dd/DD/d/D 日期   
    // hh/HH/h/H 时间   
    // mm/m 分钟   
    // ss/SS/s/S 秒   
    DateTime:function(FormatStr)
    {
    //Tue Oct 07 2008 11:36:22 GMT+0800
    var str = FormatStr;  
    var TempDate=new Date();
    var Week = ['日','一','二','三','四','五','六'];   
                    //这里是获取年分的 你想咋加就咋加
    str=str.replace(/yyyy|YYYY/,TempDate.getFullYear());    
    str=str.replace(/yy|YY/,(TempDate.getYear() % 100)>9?(TempDate.getYear() % 100).toString():'0' + (TempDate.getYear() % 100));    
    //获取月份似乎有问题 我这里要加1
    str=str.replace(/MM/,TempDate.getMonth()>9?(TempDate.getMonth()+1):'0' + (TempDate.getMonth()+1));    
    str=str.replace(/M/g,TempDate.getMonth()+1);    
    str=str.replace(/w|W/g,Week[TempDate.getDay()]);    
    str=str.replace(/dd|DD/,TempDate.getDate()>9?TempDate.getDate().toString():'0' + TempDate.getDate());    
    str=str.replace(/d|D/g,TempDate.getDate());    
    str=str.replace(/hh|HH/,TempDate.getHours()>9?TempDate.getHours().toString():'0' + TempDate.getHours());    
    str=str.replace(/h|H/g,TempDate.getHours());    
    str=str.replace(/mm/,TempDate.getMinutes()>9?TempDate.getMinutes().toString():'0' + TempDate.getMinutes());    
    str=str.replace(/m/g,TempDate.getMinutes());    
    str=str.replace(/ss|SS/,TempDate.getSeconds()>9?TempDate.getSeconds().toString():'0' + TempDate.getSeconds());    
    str=str.replace(/s|S/g,TempDate.getSeconds()); 
    //根据点数取AM或PM
    str=str.replace(/xx|XX/g,TempDate.getHours()>11?"PM":"AM");
    return str;    
    }