script
創(chuàng)新互聯(lián)建站是一家專注于成都網(wǎng)站制作、做網(wǎng)站、外貿(mào)營銷網(wǎng)站建設(shè)與策劃設(shè)計(jì),新化網(wǎng)站建設(shè)哪家好?創(chuàng)新互聯(lián)建站做網(wǎng)站,專注于網(wǎng)站建設(shè)10多年,網(wǎng)設(shè)計(jì)領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:新化等地區(qū)。新化做網(wǎng)站價(jià)格咨詢:18982081108
var d=new Date();
var dt=new Date();
dt.setFullYear(d.getFullYear(),5,7);
if(dtd)
{
dt.setFullYear(d.getFullYear()+1,5,7);
}
document.write("離高考還有"+(dt-d)/3600/24/1000+"天");
/script
改了,加了個(gè)判斷。剛理解錯(cuò)了。。
這是2014年高考倒計(jì)時(shí)的代碼,可以自己修改只需要更改BirthDay=new Date("7-6-2014"); 里面的數(shù)字就可以。測試可用。
!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""
html xmlns=""
head
meta http-equiv="Content-Type" content="text/html; charset=utf-8" /
title無標(biāo)題文檔/title
/head
body onload="show_date_time()"
SCRIPT language=javascript
function show_date_time(){
window.setTimeout("show_date_time()", 1000);
BirthDay=new Date("7-6-2014");
today=new Date();
timeold=(BirthDay.getTime()-today.getTime());
sectimeold=timeold/1000
secondsold=Math.floor(sectimeold);
msPerDay=24*60*60*1000
e_daysold=timeold/msPerDay
daysold=Math.floor(e_daysold);
e_hrsold=(e_daysold-daysold)*24;
hrsold=Math.floor(e_hrsold);
e_minsold=(e_hrsold-hrsold)*60;
minsold=Math.floor((e_hrsold-hrsold)*60);
seconds=Math.floor((e_minsold-minsold)*60);
span_dt_dt.innerHTML="balign=centerfont color=00CC00"+daysold+"天"+hrsold+"小時(shí)"+minsold+"分"+seconds+"秒"+"/bbr/font" ;
}
/SCRIPT
balign=centerfont color=#ffffff高考倒計(jì)時(shí)還有:/b/font
span id="span_dt_dt" style='align=center no:1px solid black;background-color:#FFFFFF' /span
/body
/html
!DOCTYPE?html
html
head
meta?charset="utf-8"
script?type="text/javascript"
window.onload?=?function(){
function?DistenceOfDate(year,month,day,hour,minute,seconds)?{
var?date?=?new?Date();
var?dateMill?=?date.getTime();
var?targetDate?=?new?Date(year,(month?-1),day,hour,minute,seconds);
var?targetMill?=?targetDate.getTime();
var?perDay?=?3600?*?1000?*?24;
var?perHour?=?3600*1000;
var?perMin?=?60000;
var?perSec?=?1000;
var?offset?=?targetMill?-?dateMill?;
var?tmp?=??offset?%?perDay;
var?days?=?parseInt(offset?/?perDay);
log(days);
var?offsetHour?=?tmp?%?perHour?;
var?hours?=?parseInt(tmp/?perHour);
log(hours);
var?offsetMin?=?offsetHour?%?perMin?;
var?min?=?parseInt(offsetHour?/perMin?);
log(min);
var?offsetSec?=?offsetMin?%?perSec?;
var?secs?=?parseInt(offsetMin?/perSec?);
log(secs);
log(offsetSec);
function?log?(str){
console.log(str);
}
return{
day:days,
h:hours,
m:min,
s:secs,
ms:offsetSec
}
}
setInterval(function(){
var?obj??=?DistenceOfDate(2014,11,30,00,00,00);
document.querySelector("#msg.msg").innerHTML?="距離?2014年11月30日0時(shí)0分0秒還有:/br"+obj.day+"?天?"+obj.h+"?小時(shí)?"+obj.m+"?分鐘"+
obj.s+"秒?";
},1000);
}
/script
style?type="text/css"
.msg{
width:?100%;
height:?40px;
background:?#1990d5;
color:#FBBDEE;
text-align:?center;
}
/style
/head
body
div?id="msg"?class="msg"/div
/body
/html
剛寫的熱乎的。程序精確到秒啦
var scount = 0;
$(function () {
var start = setInterval(function () {
var dtstr = "";
var now = new Date();//初始化當(dāng)前時(shí)間
var newdatr = new Date(now.getFullYear(), "05", "07", "00", "00", "00", "00");//初始化目標(biāo)時(shí)間(這里的05實(shí)際上是六月)
var nowhms = now.getTime();//當(dāng)前時(shí)間轉(zhuǎn)換毫秒
var newhms = newdatr.getTime();//目標(biāo)時(shí)間轉(zhuǎn)換毫秒
var cha = newhms - nowhms;//時(shí)間差(毫秒數(shù))
if (cha 0) {
var day = parseInt(cha / (1000 * 60 * 60 * 24));//計(jì)算天數(shù)
var hh = parseInt((cha % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));//計(jì)算小時(shí)
var min = parseInt(((cha % (1000 * 60 * 60 * 24)) % (1000 * 60 * 60)) / (1000 * 60));//計(jì)算分鐘
var ss = parseInt((((cha % (1000 * 60 * 60 * 24)) % (1000 * 60 * 60)) % (1000 * 60)) / 1000);//計(jì)算秒
if (ss == 0) {
scount += 1;
}
//var ms = parseInt((((cha % (1000 * 60 * 60 * 24)) % (1000 * 60 * 60)) % (1000 * 60)) % 1000);
dtstr = day + "天" + hh + "小時(shí)" + min + "分鐘" + ss + "秒";//+ ms + "毫秒";
}
$("#timestr").html(dtstr);
$("#flag").html("你已經(jīng)續(xù)了" + scount + "分鐘。");
}, 1000);
});