日期:2014-05-16  浏览次数:20388 次

js日期问题
function nextDay(everyDate){
  var s1=everyDate;
s1 = s1.replace('-', '/');
var date = new Date(s1);
var lIntval = 1;
date.setDate(date.getDate() + lIntval);
//newD=date.getYear() +'-' + (date.getMonth()+1) + '-' +date.getDate();
newE=date.getYear() +'年' + (date.getMonth()+1) + '月' +date.getDate()+'日';
return newE;
}

alert(nextDay("2011-01-01"));

在火狐上提示NaN,请问怎么修改才能正常显示呢?

------解决方案--------------------
s1 = s1.replace(/\-/g, '/');
------解决方案--------------------
<script>
function nextDay(everyDate) {
var s1 = everyDate;

s1 = s1.replace(/\-/g, '/');

var date = new Date(s1);

var lIntval = 1;

date.setDate(date.getDate() + lIntval);

newE = date.getFullYear() + '年' + (date.getMonth() + 1) + '月' + date.getDate() + '日';

return newE;
}
alert(nextDay("2011-01-01"));

</script>
------解决方案--------------------
JScript code

<script>
        function nextDay(everyDate) {
            var s1 = everyDate;
            
            s1 = s1.replace(/\-/g, '/');

            var date = new Date(s1);
           
            var lIntval = 1;
            
            date.setDate(date.getDate() + lIntval);

            newE = date.getFullYear() + '年' + (date.getMonth() + 1) + '月' + date.getDate() + '日';
            
            return newE;
        }
        alert(nextDay("2011-01-01"));

    </script>

------解决方案--------------------
s1 = s1.split('-');
var date = new Date(s1[0],s1[1],s1[2]);
------解决方案--------------------
s1 = s1.replace('-', '/');出了问题,得到的s1值为'2011/01-10',不能被解析成日期,使用s1 = s1.replace(/-/g, '/');即可
------解决方案--------------------
用getFullYear()
------解决方案--------------------
newE = date.getFullYear() + '年' + (date.getMonth() + 1) + '月' + date.getDate() + '日';