更新時間:2023-11-09 21:07:41作者:佚名
使用獲取系統當前的日期時間美國時間現在幾點查詢 美國今天是幾月幾號星期幾美國時間現在幾點查詢 美國今天是幾月幾號星期幾,獲取到的當前時間具體到年、月、日,時、分、秒以及當前是禮拜幾。時間也是在不停地走動的,簡單又實用。
1、Html部份:
<div class="plane">
<a id=clock></a>
</div>
2、JS實現代碼:
<script type="text/javascript">
//==================獲取系統當前詳細日期時間=================
var clock = new Clock();
clock.display(document.getElementById("clock"));
function Clock() {
var date = new Date();//實例一個時間對象
this.year = date.getFullYear();//獲取完整的年份(4位)
this.month = date.getMonth() + 1;//獲取當前月份,由于月份從0開始計算,要+1
this.date = date.getDate();//獲取當前日(1-31)
this.day = new Array("星期日", "星期一", "星期二", "星期三",
"星期四", "星期五", "星期六")[date.getDay()];//獲取星期
this.hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();//獲取當前小時數(0-23)
this.minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();//獲取當前分鐘數(0-59)
this.second = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();//獲取當前秒數(0-59)
//當前詳細日期時間
this.toString = function () {
return "現在是:" + this.year + "年" + this.month + "月" + this.date + "日 " + this.hour + ":" + this.minute + ":" + this.second + " " + this.day;
};
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);
};
}
</script>
3、實現療效: