JS常用工具类
date类
var date = new Date();//当前日期
var year = date.getFullYear();//年份
var month = date.getMonth()+1;//月份(从0开始的所以加1)
var day = date.getDate();//哪一天 (1-31)
var house = date.getHours();//时 24小时制
var min = date.getMinutes();//分
var sec = date.getSeconds();//秒
var d = year+"-"+month+"-"+day+" "+house+":"+min+":"+sec;//组合时间
console.log(d);
定时器
<html>
<head>
<script>
var time;
(function setSpan(){
console.log(222);
time = setInterval(getDate,1000);
})();
function getDate(){
var s = document.getElementById("s");
var date = new Date();
var year = date.getFullYear();
var month = date.getMonth()+1;
var day = date.getDate();
var house = date.getHours();
var min = date.getMinutes();
var sec = date.getSeconds();
month = month<10?"0"+month:month;
day = day<10?"0"+day:day;
house = house<10?"0"+house:house;
min = min<10?"0"+min:min;
sec = sec<10?"0"+sec:sec;
var d = year+"-"+month+"-"+day+" "+house+":"+min+":"+sec;
s.innerHTML = d;
}
//清空定时器
function clears(){
clearTimeout(time);
}
</script>
</head>
<body>
<span id="s"></span>
<button onclick="clears()">清除定时器</button>
</body>
</html>
setInterval(function, milliseconds) | 设置定时器 |
---|---|
clearTimeout() | 清空定时器 |
常用对象String
案例
Array对象
案例
Math对象
Number对象
原文地址:https://blog.csdn.net/weixin_64922330/article/details/140574040
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!