2007年8月31日 星期五

Blog顯示衛星雲圖(動態進階版)

<img id="MTSAT" width="200" height="215" onerror="ChangePicture()">
<SCRIPT language="javascript">
var PictureNumber=6;

var GoPicrures="";
var previousPicrures="";
var NextPicrures="";
var HttpUrls="";
var now = new Date();
var years = now.getYear();
var months = now.getMonth()+1;
var days = now.getDate();
var hours = now.getHours();

HttpUrls=imgurl(years,months,days,hours);
MTSAT.src=HttpUrls;
for(i=(-1)*(PictureNumber-1);i<=0;i++){
NextNow = addDate(years,months-1,days,hours,0,i);
years_tmp = NextNow.getYear();
months_tmp = NextNow.getMonth()+1;
days_tmp = NextNow.getDate();
hours_tmp = NextNow.getHours();
if(i<0){
GoPicrures+=","+imgurl(years_tmp,months_tmp,days_tmp,hours_tmp);
}else{
NextPicrures=imgurl(years_tmp,months_tmp,days_tmp,hours_tmp);
}
}

function addDate(dy,dmomth,dd,dh,dm,dadd){
var a = new Date(dy,dmomth,dd,dh,dm)
a = a.valueOf()
a = a + dadd * 1 * 60 * 60 * 1000
a = new Date(a)
return a;
}

function imgurl(dy,dm,dd,dh){
// AreaType 參數 ( 全球:s0p 東亞:s1p 台灣:s3p )
AreaType="s1p";
FileName = AreaType + "-";
FileName += dy+"-";
FileName += ((dm < 10) ? "0" : "") + dm + "-";
FileName += ((dd < 10) ? "0" : "") + dd + "-";
FileName += ((dh < 10) ? "0" : "") + dh + "-00.jpg";
return "http://www.cwb.gov.tw/V6/observe/satellite/Data/" + AreaType + "/" + FileName;
}

function ChangePicture(){
NextNow = addDate(years,months-1,days,hours,0,(-1)*(PictureNumber-1));
years_tmp = NextNow.getYear();
months_tmp = NextNow.getMonth()+1;
days_tmp = NextNow.getDate();
hours_tmp = NextNow.getHours();
previousPicrures=imgurl(years_tmp,months_tmp,days_tmp,hours_tmp);
MTSAT.src=previousPicrures;
}

function ActivePicture(i){
StrLen=previousPicrures.length;
if(StrLen){
GoPicrures_tmp=GoPicrures+","+NextPicrures;
}else{
GoPicrures_tmp=","+previousPicrures+GoPicrures;
}
UrlPicrures=GoPicrures_tmp.split(",");
//alert(i+"="+UrlPicrures[i])
MTSAT.src=UrlPicrures[i];
PictureCount=UrlPicrures.length-1;
if(i==PictureCount){
i=1;
}else{
i++;
}
setTimeout("ActivePicture("+i+")",1500)
}
ActivePicture(1);
</SCRIPT>

Blog顯示衛星雲圖

<img id="MTSAT" width="200" height="215" onerror="ChangePicture()">
<SCRIPT language="javascript">
function addDate(dy,dmomth,dd,dh,dm,dadd){

var a = new Date(dy,dmomth,dd,dh,dm)
a = a.valueOf()
a = a + dadd * 1 * 60 * 60 * 1000
a = new Date(a)
return a;
}

function imgurl(dy,dm,dd,dh){
// AreaType 參數 ( 全球:s0p 東亞:s1p 台灣:s3p )
AreaType="s1p";
FileName = AreaType + "-";
FileName += dy+"-";
FileName += ((dm < 10) ? "0" : "") + dm + "-";
FileName += ((dd < 10) ? "0" : "") + dd + "-";
FileName += ((dh < 10) ? "0" : "") + dh + "-00.jpg";
return "http://www.cwb.gov.tw/V6/observe/satellite/Data/" + AreaType + "/" + FileName;
}
var HttpUrls="";
var now = new Date();
var years = now.getYear();
var months = now.getMonth()+1;
var days = now.getDate();
var hours = now.getHours();
var minutes = now.getMinutes();

HttpUrls=imgurl(years,months,days,hours);

MTSAT.src=HttpUrls;

function ChangePicture(){
if(hours==0){
NextNow = addDate(years,months-1,days,hours,0,-1);
years = NextNow.getYear();
months = NextNow.getMonth()+1;
days = NextNow.getDate();
hours = NextNow.getHours();
}else{
hours-=1;
}
HttpUrls=imgurl(years,months,days,hours);
MTSAT.src=HttpUrls;
}
</SCRIPT>

JavaScript 找前一天日期

<SCRIPT language="javascript">
function addDate(dd,dadd){
var a = new Date(dd)
a = a.valueOf()
a = a + dadd * 24 * 60 * 60 * 1000
a = new Date(a)
return a;
}

//抓取現在日期

var now = new Date();
var years = now.getYear();
var months = now.getMonth()+1;
var days = now.getDate();
var hours = now.getHours();

//抓取前一天日期

NextNow = addDate(months+"/"+days+"/"+years,-1);
years = NextNow.getYear();
months = NextNow.getMonth()+1;
days = NextNow.getDate();

alert("前一天日期:"+years+"年"+months+"月"+days+"日");

</SCRIPT>