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

帮忙啊,获取时间问题
是这样的,

var   today   =   new   Date();
times   =   (today.getYear()+1)+ "- "+(today.getMonth()+1)+ "- "+today.getDate()

这句的意思是在现有的时间基础上加上一年
在IE里面是运行正确的

但是在firefox里面就不正确,我在网上查了下,要变成
times   =   (1900+today.getYear()+1)+ "- "+(today.getMonth()+1)+ "- "+today.getDate()
才行,也就是要加上1900,firefox里可以了,但是IE里又不对了
怎么统一呢?有没有其他办法呢?


------解决方案--------------------
可以用
.getFullYear()
------解决方案--------------------
var today = new Date();
var dt = new Date(today.getFullYear()+1, today.getMonth(), today.getDate());
alert(dt.getFullYear() + "- " + (dt.getMonth()+1) + "- " + dt.getDate())
------解决方案--------------------
var now = new Date();
now.setFullYear(now.getFullYear() + 1); //这样就在原时间基础上加了一年

alert(now);