年月日,时分秒,周几

HTML:
<div class="checktime">
       <div class="date"></div>
           <div>
               <span class="day"></span>
               <span class="time"></span>
           </div>
  </div>
//引入  time.js  和 gettime.js
//[gettime.js  部份]

‘use strict’;

var week_arr = ['日', '一', '二', '三', '四', '五', '六'];
 // 补零函数
 function addZero(num) {
return num >= 10 ? num : '0' + num;
}
// 获取时间函数
function getTime() {
    var data = new Date();
    var Hours = addZero(data.getHours());
    var Minute = addZero(data.getMinutes());
    var Year = data.getFullYear();
    var Month = addZero(data.getMonth()+1);
    var Second= addZero(data.getSeconds());
    // 周几
    var Day = data.getDay();
    // 日期天
    var date = addZero(data.getDate());

    return {
        Hours: Hours,
        Minute: Minute,
        Year: Year,
        Month: Month,
        Second:Second,
        Day: Day,
        date: date,
    };
}

 ;(
// 获取时间函数,页面直接展示
function() {
    var data = new Date();
    var Hours = addZero(data.getHours());
    var Minute = addZero(data.getMinutes());
    var Year = data.getFullYear();
    var Month = addZero(data.getMonth()+1);
    var Second= addZero(data.getSeconds());
    // 周几
    var Day = data.getDay();
    // 日期天
    var date = addZero(data.getDate());

    window.TIME = {
        Hours: Hours,
        Minute: Minute,
        Year: Year,
        Month: Month,
        Second:Second,
        Day: Day,
        date: date
    };
})(); 

 //[time.js  部份]
 //获取到页面上时间所处于的位置,并把时间放入页面内
 var date = document.getElementsByClassName('date')[0];
var day = document.getElementsByClassName('day')[0];
var time = document.getElementsByClassName('time')[0];
date.innerText =  TIME.Year + '年' + TIME.Month + '月' +(TIME.date)+'日';
day.innerText = "周"+week_arr[TIME.Day];
time.innerText = (TIME.Hours) + " : " +(TIME.Minute);
	var goback = document.getElementsByClassName('goback')[0];
function getTime1(){
	 var TIME = getTime();//调用  getTime.js 
	date = document.getElementsByClassName('date')[0];
	day = document.getElementsByClassName('day')[0];
	time = document.getElementsByClassName('time')[0];
	date.innerText =  TIME.Year + '年' + TIME.Month + '月' +(TIME.date)+'日';
	day.innerText = "周"+week_arr[TIME.Day];
	time.innerText = (TIME.Hours) + " : " +(TIME.Minute) + ":" +(TIME.Second);
	var goback = document.getElementsByClassName('goback')[0];
}
setInterval(function(){
	getTime1(); 
},1000)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值