1、时间对象
var oDate=new Date();
oDare.getFulLYear(); //年
oDate.getMonth(); //月 从0开始的(用的时候需考虑加1)
oDate.getDate(); //日
oDate.getDay(); //星期
oDate.getHours(); //时
oDate.getMiuntes(); //分
oDate.getSeconde() //秒
2、设置时间(未来时间)
var oFDate=new Date();
oFDate.setFullYear(年,月,日);
oFDate.setHours(10,8,7,6); //时,分,秒,毫秒
oFDate.setMonth(月);
oFDate.setDate(日);
注:setDate(32); 自动进位到下个月第一天;
setDate(0); 自动退位到上个月最后一天
3、获取这个月是多少天
var oDate=new Date();
var nowMonth=oDate.getMonth()+1; //先获取时间
var nextMonth=oDate.setMonth(nowMonth); //设置到下个月
oDate.setDate(0); //设置日期为0
alert(oDate.getDate); //获取时间
4、获取本月1号是星期几;
var oDate=new Date();
oDate.setDate(1);
alert(oDate.getDay());
5、倒计时
window.onload=function(){
var oBox=document.getElementById('box');
var oFDate=new Date();
oFDate.setFullYear(2016,9,1);
oFDate.setHours(0,0,0,0);
oFDate.getTime();
//alert(s);
function ms(){
var oDate=new Date();
var oNDate=oDate.getTime();
var ms=s-oNDate;
var S=parseInt(ms/1000);
var d=parseInt(S/86400);
S=S%86400;
var h=parseInt(S/3600);
S=S%3600;
var M=parseInt(S/60);
S=S%60;
oBox.innerHTML='还有'+toDou(d)+'天'+toDou(h)+'时'+toDou(M)+'分'+toDou(S)+'秒';
}
ms();
setInterval(ms,1000);
};
网友评论