日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

javascript顯示當前日期時間和當前為本年第幾周

系統 2127 0

運行效果:

javascript文件:

function Clock() {
var date = new Date();
this.year = date.getFullYear();
this.month = date.getMonth() + 1;
this.date = date.getDate();
this.day = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六")[date.getDay()];
this.hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
this.minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
this.second = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();

// 計算日期為當年的第幾周
function weekOfYear(year, month, day){
// year年 month月 day日
// 每周從周日開始
var date1 = new Date(year, 0, 1);
var date2 = new Date(year, month-1, day, 1);
var dayMS = 24*60*60*1000;
var firstDay = (7-date1.getDay())*dayMS;
var weekMS = 7*dayMS;
date1 = date1.getTime();
date2 = date2.getTime();
return Math.ceil((date2-date1-firstDay)/weekMS)+1;
}

this.toString = function() {
return "現在是:" + this.year + "年" + this.month + "月" + this.date + "日 " + this.hour + ":" + this.minute + ":" + this.second + " " + this.day
+" 今年第"+weekOfYear(this.year,this.month,this.date)+"周";
};

this.toSimpleDate = function() {
return this.year + "-" + this.month + "-" + this.date;
};

this.toDetailDate = function() {
return this.year + "-" + this.month + "-" + this.date + " " + this.hour + ":" + this.minute + ":" + this.second;
};

this.display = function(ele) {
var clock = new Clock();
ele.innerHTML = clock.toString();
window.setTimeout(function() {clock.display(ele);}, 1000);
};
}

html文件:

<html>
<head>
<title>clock</title>
<script src="Clock.js" type="text/javascript"></script>
</head>
<body>
<span id="clock"></span>
<script type="text/javascript">
var clock = new Clock();
clock.display(document.getElementById("clock"));
</script>
</body>
</html>

javascript顯示當前日期時間和當前為本年第幾周


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦?。。?/p>

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 东阿县| 江西省| 扬中市| 阳西县| 玉林市| 鄂州市| 广灵县| 高台县| 临高县| 镶黄旗| 淮滨县| 大名县| 交口县| 黄大仙区| 平山县| 九寨沟县| 江永县| 墨江| 保德县| 汝州市| 和平区| 泾川县| 大石桥市| 佛冈县| 凤庆县| 乌拉特中旗| 青田县| 璧山县| 白水县| 湟中县| 奉化市| 伊通| 霍邱县| 焦作市| 汝阳县| 德惠市| 彭阳县| 玛多县| 屯昌县| 兴化市| 富民县|