网站运行时间代码

样式一:

<span> 本站已运行</span><span id="span_dt_dt"></span><script> /*建站时间*/ function show_date_time() { window.setTimeout("show_date_time()", 1e3); var BirthDay = new Date("2018/03/01"), today = new Date, timeold = today.getTime() - BirthDay.getTime(), msPerDay = 864e5, e_daysold = timeold / msPerDay, daysold = Math.floor(e_daysold), e_hrsold = 24 * (e_daysold - daysold), hrsold = Math.floor(e_hrsold), e_minsold = 60 * (e_hrsold - hrsold), minsold = Math.floor(60 * (e_hrsold - hrsold)), seconds = Math.floor(60 * (e_minsold - minsold)); span_dt_dt.innerHTML = daysold + "天" + hrsold + "小时" + minsold + "分" + seconds + "秒"; } show_date_time();</script>

样式二:

当前系统时间<span id="nowTime"></span><script type="text/javascript">//获取系统时间var newDate = '';getLangDate();//值小于10时,在前面补0function dateFilter(date){ if(date < 10){return "0"+date;} return date;}function getLangDate(){ var dateObj = new Date(); //表示当前系统时间的Date对象 var year = dateObj.getFullYear(); //当前系统时间的完整年份值 var month = dateObj.getMonth()+1; //当前系统时间的月份值 var date = dateObj.getDate(); //当前系统时间的月份中的日 var day = dateObj.getDay(); //当前系统时间中的星期值 var weeks = ["星期日","星期一","星期二","星期三","星期四","星期五","星期六"]; var week = weeks[day]; //根据星期值,从数组中获取对应的星期字符串 var hour = dateObj.getHours(); //当前系统时间的小时值 var minute = dateObj.getMinutes(); //当前系统时间的分钟值 var second = dateObj.getSeconds(); //当前系统时间的秒钟值 var timeValue = "" +((hour >= 12) ? (hour >= 18) ? "晚上" : "下午" : "上午" ); //当前时间属于上午、晚上还是下午 newDate = dateFilter(year)+"年"+dateFilter(month)+"月"+dateFilter(date)+"日 "+" "+dateFilter(hour)+":"+dateFilter(minute)+":"+dateFilter(second); document.getElementById("nowTime").innerHTML = timeValue+"好!当前时间为: "+newDate+" "+week; setTimeout("getLangDate()",1000);}</script>
阿强爱分享
  • 本文由 发表于 2019年8月7日09:21:39
  • 转载请务必保留本文链接:https://iooqp.cn/454.html
匿名

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: