<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Date</title>
</head>
<body>
<div id="div1"></div>
<script type="text/javascript">
/*
* JS里,date表示时间和日期
*/
//1.获取当前时间
// var now = new Date();
alert(now);
// //2.获取年份
// var year = now.getFullYear();
// console.log(typeof year);
// //3.获取月份 月份值 0 ~ 11
// var month = now.getMonth();
// console.log(month);
// //4.获取星期几
// var day = now.getDay();
// console.log(day);
// //5.获取当天
// var today = now.getDate()
// console.log(today);
// //6.获取小时 24小时
// var hour = now.getHours();
// console.log(hour);
// //7.获取分钟
// var minute = now.getMinutes();
// console.log(minute);
// //8.获取秒
// var second = now.getSeconds();
// console.log(second);
// //9.获取时间戳
// //1970.1.1 距离现在的时间
// var times = now.getTime();
// console.log(times);
// function get_clock(){
// var now = new Date();
// var year = now.getFullYear();
// var month = now.getMonth();
// var today = now.getDate();
// var day = now.getDay();
// var hour = now.getHours();
// if (hour < 10){
// hour = "0" + hour;
// }
// var minute = now.getMinutes();
// if (minute < 10){
// minute = "0" + minute;
// }
// var second = now.getSeconds();
// if (second < 10){
// second = "0" + second;
// }
// document.getElementById("div1").innerHTML = year + "-" + (month+1) + "-" +today +" "+ "星期" + day +" "+ hour + ":" + minute +":" + second;
//
// }
// clearInterval(times)
// times = setInterval(get_clock, 1000);
/*
* new Date();可以创建任意时间点的时间对象
* 将想要获取的时间点以参数的形式传入Date()函数里
*
*/
// alert(tomorrow);
function future(){
var tomorrow = new Date(2016,9,15,16,0,0);
var now = new Date();
var times = (tomorrow.getTime()-now.getTime())/1000;
var d = Math.floor(times / 60 / 60 / 24);
var h = Math.floor(times /60 / 60);
var m = Math.floor(times / 60 % 60);
var s = Math.floor(times % 60 );
document.getElementById("div1").innerHTML = "倒计时剩余" + d +"天" + h +"小时"+ m +"分钟" + s + "秒";
}
setInterval(future,1000);
</script>
</body>
</html>