网站自定义运行时间和当前时间和天气代码
代码如下,附在网页代码即可。文字可适当修改,自测。
<script language=javascript>
function siteTime(){
window.setTimeout("siteTime()", 1000);
var seconds = 1000
var minutes = seconds * 60
var hours = minutes * 60
var days = hours * 24
var years = days * 365
var today = new Date()
var todayYear = today.getFullYear()
var todayMonth = today.getMonth()
var todayDate = today.getDate()
var todayHour = today.getHours()
var todayMinute = today.getMinutes()
var todaySecond = today.getSeconds()
var t1 = Date.UTC(2016,1,13,6,00,00)
var t2 = Date.UTC(todayYear,todayMonth,todayDate,todayHour,todayMinute,todaySecond)
var diff = t2-t1
var diffYears = Math.floor(diff/years)
var diffDays = Math.floor((diff/days)-diffYears*365)
var diffHours = Math.floor((diff-(diffYears*365+diffDays)*days)/hours)
var diffMinutes = Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours)/minutes)
var diffSeconds = Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours-diffMinutes*minutes)/seconds)
document.getElementById("sitetime").innerHTML="<br><center><b>迄今已运行 "+diffYears+' 年 '+diffDays+" 天 "+diffHours+" 时 "+diffMinutes+" 分 "+diffSeconds+" 秒</b></center>"
}
siteTime()
</script>
<script type="text/javascript">
$('#weather').leoweather({format:'<strong>{年}年{月}月{日}日 星期{周} {时}:{分}:{秒}</strong>,</span> <b>{城市} {天气} {夜间气温}℃ ~ {白天气温}℃</b>'});
</script>
商业转载请联系作者获得授权,非商业转载请注明本文出处及文章链接