给定目标地区时区,在js中求得时间
<script type="text/javascript"
language="javascript"><!--
function calcTime(offset) {
//create
Date object for current location
d = new
Date();
//convert to
msec
//add local
time zone offset
//get UTC
time in msec
utc =
d.getTime() + (d.getTimezoneOffset() * 60000);
//create new
Date object for different city
//using
supplied offset
nd = new
Date(utc + (3600000*offset));
return
nd;
}
var offset_time = -8;//目标地区的时区
var year = 2012;
var month = 2;
var day = 8;
var hours = 18;
var minutes = 00;
var seconds=00;
var endStr = year+'/'+month+'/'+day+' '+hours+':'+minutes+':'+seconds;
var endDate=new Date(endStr);
var total_seconds = 0;
var now = calcTime(offset_time);
total_seconds=(endDate.getTime()-now.getTime())/1000;
total_seconds = Math.round(total_seconds);
setInterval('exe()',1000);
function exe(){
if(total_seconds > 0){
var hh = Math.floor(total_seconds/3600);
var mm =
Math.floor((Number(total_seconds)-Number(Number(hh)*3600))/60);
var ss =
Number(total_seconds)-Number(Number(hh)*3600)-Number(Number(mm)*60);
if(hh < 10) hh='0'+hh;
if(mm < 10) mm = '0'+mm;
if(ss < 10) ss = '0'+ss;
document.getElementByIdx_x('DDtime').innerHTML=
hh+':'+mm+':'+ss;
total_seconds--;
}else{
document.getElementByIdx_x('DDtime').innerHTML=
'00:00:00';
}
}
--></script>
function calcTime(offset) {
}
var offset_time = -8;//目标地区的时区
var year = 2012;
var month = 2;
var day = 8;
var hours = 18;
var minutes = 00;
var seconds=00;
var endStr = year+'/'+month+'/'+day+' '+hours+':'+minutes+':'+seconds;
var endDate=new Date(endStr);
var total_seconds = 0;
var now = calcTime(offset_time);
total_seconds=(endDate.getTime()-now.getTime())/1000;
total_seconds = Math.round(total_seconds);
setInterval('exe()',1000);
function exe(){
}
--></script>
网络上志同道合,我们一起学习网络安全,一起进步,QQ群:694839022