<script type="text/javascript">
clock();//一开始来去初始化倒计时
setInterval(clock,1000)
function clock () {
//这里是给当前创建的时间对象 一个具体的日期
var targetTime = new Date('2019-05-30 00:00:00');
//创建当前时间对象
var nowTime = new Date();
//可以通过两个时间直接相减 来去得两个时间相差的 毫秒数
//两者相减可以得到相应相差多少毫秒值
//除于1000 就能够得到 相差的秒数
var time = (targetTime - nowTime)/1000;
var t = parseInt(time/86400);//相差的天数
//9.5小时
var hr = parseInt(time%86400/3600);//剩余时间可以转化为多少整数小时
var min = parseInt(time%3600/60);//剩余时间可以转化为多少整数分钟
var sec = parseInt(time%60);//剩余时间可以转化为多少整数秒
var str = '当前时间到2019年5月30号零点还有'+t+'天'+' '+hr+'时'+min+'分'+sec+'秒';
document.body.innerHTML = str;
}
//console.log(sec);
//console.log(targetTime - nowTime)
//console.log(1559145600000 - 1557901417000)
//console.log(nowTime.getHours());//输出日期
//如果说要理解这个倒计时的原理 应该先知道 时间戳
//时间戳 是代表1900 到目标时间的 毫秒数
//比如说 1900 到 2019-05-30 00:00:00 的毫秒数 1559145600000
//1900 到 2019-05-15 14:13:31 1557900811000
//这一段数值 就是哪个时间点 相应的时间戳
//如果5月30号的时间戳 - 5月15号的时间戳 = 两个时间点 相差的毫秒数 time
//一天是 86400s 86400000ms
//parseint(time/86400000) = 相差的天数
//parseint time%86400000/3600000 = 小时
//parseint time%3600000/60 = 分钟
//parseint time%60 = 秒数
</script>
<script type="text/javascript">
// 时钟
ou();
setInterval(ou,1000)
function ou(){
var time = new Date();
var a = time.getFullYear();
var b = time.getMonth()+1;
var c = time.getDate();
var d = time.getHours();
var e = time.getMinutes();
var f = time.getSeconds();
var g = time.getDay();
var week = ['星期天','星期一','星期二','星期三','星期四','星期五','星期六'];
var str = a+'/'+b+'/'+c+' '+getStr(d)+':'+getStr(e)+':'+getStr(f);
document.body.innerHTML=str+week[g];
// document.body.innerHTML = week[c];
}
function getStr (num) {
num = num<10? '0'+num : num;
return num;
}
// 倒计时
var localTime = new Date('2019-05-30 00:00:00');
var nowTime = new Date();
var time = (localTime-nowTime)/1000;
// 字符串
var str='string';
var str2 = 'FBVZFB'
var str1=String('string');
console.log(str.length);
console.log(str.charAt(1));
// charCodeAt编码值
console.log(str.charCodeAt(0));
console.log('a'>'3');
console.log(str.indexOf('g'));
console.log(str.substring(1,5));
console.log(str2.toLowerCase());
console.log(str.toUpperCase());
</script>