zoukankan      html  css  js  c++  java
  • 天气和滚动的日期时间

    上下滚动的天气

    1 <iframe width="300" scrolling="no" height="20" frameborder="0" allowtransparency="true" src="http://i.tianqi.com/index.php?c=code&id=10&icon=3"></iframe>

    滚动的日期时间

    直接引入js即可

    <script type="text/javascript" src="./js/date.js"></script>
      1 <!--
      2 var lunarInfo=new Array(
      3 0x04bd8,0x04ae0,0x0a570,0x054d5,0x0d260,0x0d950,0x16554,0x056a0,0x09ad0,0x055d2,
      4 0x04ae0,0x0a5b6,0x0a4d0,0x0d250,0x1d255,0x0b540,0x0d6a0,0x0ada2,0x095b0,0x14977,
      5 0x04970,0x0a4b0,0x0b4b5,0x06a50,0x06d40,0x1ab54,0x02b60,0x09570,0x052f2,0x04970,
      6 0x06566,0x0d4a0,0x0ea50,0x06e95,0x05ad0,0x02b60,0x186e3,0x092e0,0x1c8d7,0x0c950,
      7 0x0d4a0,0x1d8a6,0x0b550,0x056a0,0x1a5b4,0x025d0,0x092d0,0x0d2b2,0x0a950,0x0b557,
      8 0x06ca0,0x0b550,0x15355,0x04da0,0x0a5d0,0x14573,0x052d0,0x0a9a8,0x0e950,0x06aa0,
      9 0x0aea6,0x0ab50,0x04b60,0x0aae4,0x0a570,0x05260,0x0f263,0x0d950,0x05b57,0x056a0,
     10 0x096d0,0x04dd5,0x04ad0,0x0a4d0,0x0d4d4,0x0d250,0x0d558,0x0b540,0x0b5a0,0x195a6,
     11 
     12 0x095b0,0x049b0,0x0a974,0x0a4b0,0x0b27a,0x06a50,0x06d40,0x0af46,0x0ab60,0x09570,
     13 0x04af5,0x04970,0x064b0,0x074a3,0x0ea50,0x06b58,0x055c0,0x0ab60,0x096d5,0x092e0,
     14 0x0c960,0x0d954,0x0d4a0,0x0da50,0x07552,0x056a0,0x0abb7,0x025d0,0x092d0,0x0cab5,
     15 0x0a950,0x0b4a0,0x0baa4,0x0ad50,0x055d9,0x04ba0,0x0a5b0,0x15176,0x052b0,0x0a930,
     16 0x07954,0x06aa0,0x0ad50,0x05b52,0x04b60,0x0a6e6,0x0a4e0,0x0d260,0x0ea65,0x0d530,
     17 0x05aa0,0x076a3,0x096d0,0x04bd7,0x04ad0,0x0a4d0,0x1d0b6,0x0d250,0x0d520,0x0dd45,
     18 0x0b5a0,0x056d0,0x055b2,0x049b0,0x0a577,0x0a4b0,0x0aa50,0x1b255,0x06d20,0x0ada0)
     19 var Animals=new Array("鼠","牛","虎","兔","龙","蛇","马","羊","猴","鸡","狗","金猪");
     20 var Gan=new Array("甲","乙","丙","丁","戊","己","庚","辛","壬","癸");
     21 var Zhi=new Array("子","丑","寅","卯","辰","巳","午","未","申","酉","戌","亥");
     22 var now = new Date();
     23 var SY = now.getFullYear(); 
     24 var SM = now.getMonth();
     25 var SD = now.getDate();
     26  
     27 //==== 传入 offset 传回干支, 0=甲子
     28 function cyclical(num) { return(Gan[num%10]+Zhi[num%12])}
     29 
     30 //==== 传回农历 y年的总天数
     31 function lYearDays(y) {
     32    var i, sum = 348
     33    for(i=0x8000; i>0x8; i>>=1) sum += (lunarInfo[y-1900] & i)? 1: 0
     34    return(sum+leapDays(y))
     35 }
     36 
     37 //==== 传回农历 y年闰月的天数
     38 function leapDays(y) {
     39    if(leapMonth(y))  return((lunarInfo[y-1900] & 0x10000)? 30: 29)
     40    else return(0)
     41 }
     42 
     43 //==== 传回农历 y年闰哪个月 1-12 , 没闰传回 0
     44 function leapMonth(y) { return(lunarInfo[y-1900] & 0xf)}
     45 
     46 //====================================== 传回农历 y年m月的总天数
     47 function monthDays(y,m) { return( (lunarInfo[y-1900] & (0x10000>>m))? 30: 29 )}
     48 
     49 //==== 算出农历, 传入日期物件, 传回农历日期物件
     50 //     该物件属性有 .year .month .day .isLeap .yearCyl .dayCyl .monCyl
     51 function Lunar(objDate) {
     52    var i, leap=0, temp=0
     53    var baseDate = new Date(1900,0,31)
     54    var offset   = (objDate - baseDate)/86400000
     55 
     56    this.dayCyl = offset + 40
     57    this.monCyl = 14
     58 
     59    for(i=1900; i<2050 && offset>0; i++) {
     60       temp = lYearDays(i)
     61       offset -= temp
     62       this.monCyl += 12
     63    }
     64    if(offset<0) {
     65       offset += temp;
     66       i--;
     67       this.monCyl -= 12
     68    }
     69 
     70    this.year = i
     71    this.yearCyl = i-1864
     72 
     73    leap = leapMonth(i) //闰哪个月
     74    this.isLeap = false
     75 
     76    for(i=1; i<13 && offset>0; i++) {
     77       //闰月
     78       if(leap>0 && i==(leap+1) && this.isLeap==false)
     79          { --i; this.isLeap = true; temp = leapDays(this.year); }
     80       else
     81          { temp = monthDays(this.year, i); }
     82 
     83       //解除闰月
     84       if(this.isLeap==true && i==(leap+1)) this.isLeap = false
     85 
     86       offset -= temp
     87       if(this.isLeap == false) this.monCyl ++
     88    }
     89 
     90    if(offset==0 && leap>0 && i==leap+1)
     91       if(this.isLeap)
     92          { this.isLeap = false; }
     93       else
     94          { this.isLeap = true; --i; --this.monCyl;}
     95 
     96    if(offset<0){ offset += temp; --i; --this.monCyl; }
     97 
     98    this.month = i
     99    this.day = offset + 1
    100 }
    101 
    102  function YYMMDD(){ 
    103     var cl = '<font color="" style="font-size:9pt;">'; 
    104     if (now.getDay() == 0) cl = '<font color="" style="font-size:9pt;">'; 
    105     if (now.getDay() == 6) cl = '<font color="" style="font-size:9pt;">';
    106     return(cl+SY+'年'+(SM+1)+'月'+SD+'日</font>'); 
    107  }
    108  function weekday(){ 
    109     var day = new Array("<font color='red'>星期日</font>","星期一","星期二","星期三","星期四","星期五","星期六");
    110     if (now.getDay() == 0) cl = '<font color="" style="font-size:9pt;">';
    111     if (now.getDay() == 6) cl = '<font color="" style="font-size:9pt;"">'; 
    112     return(day[now.getDay()]); 
    113  }
    114 //==== 中文日期
    115 function cDay(m,d){
    116  var nStr1 = new Array('日','一','二','三','四','五','六','七','八','九','十');
    117  var nStr2 = new Array('初','十','廿','卅',' ');
    118  var s;
    119  if (m>10){s = '十'+nStr1[m-10]} else {s = nStr1[m]} s += '月'
    120  switch (d) {
    121   case 10:s += '初十'; break;
    122   case 20:s += '二十'; break;
    123   case 30:s += '三十'; break;
    124   default:s += nStr2[Math.floor(d/10)]; s += nStr1[d%10];
    125  }
    126  return(s);
    127 }
    128  function solarDay1(){
    129     var sDObj = new Date(SY,SM,SD);
    130     var lDObj = new Lunar(sDObj);
    131     var tt = '【'+Animals[(SY-4)%12]+'】'+cyclical(lDObj.monCyl)+'月 '+cyclical(lDObj.dayCyl++)+'日' ;
    132     return(tt);
    133  }
    134  function solarDay2(){
    135     var sDObj = new Date(SY,SM,SD);
    136     var lDObj = new Lunar(sDObj);
    137     var cl = '<font color="" style="font-size:9pt;">'; 
    138     //农历BB'+(cld[d].isLeap?'闰 ':' ')+cld[d].lMonth+' 月 '+cld[d].lDay+' 日
    139     var tt = cyclical(SY-1900+36)+'【'+Animals[(SY-4)%12]+'】'+'年 '+cDay(lDObj.month,lDObj.day);
    140     return(cl+tt+'</font>');
    141  }
    142  function solarDay3(){
    143 var sTermInfo = new Array(0,21208,42467,63836,85337,107014,128867,150921,173149,195551,218072,240693,263343,285989,308563,331033,353350,375494,397447,419210,440795,462224,483532,504758)
    144 var solarTerm = new Array("小寒","大寒","立春","雨水","惊蛰","春分","清明","谷雨","立夏","小满","芒种","夏至","小暑","大暑","立秋","处暑","白露","秋分","寒露","霜降","立冬","小雪","大雪","冬至")
    145 var lFtv = new Array("0101*春节","0115 元宵节","0505 端午节","0707 七夕情人节","0715 中元节","0815 中秋节","0909 重阳节","1208 腊八节","1224 小年","0100*除夕")
    146 var sFtv = new Array("0101*元旦","0214*情人节","0308*妇女节","0312*植树节","0315*消费者权益日",
    147 "0401*愚人节","0422*地球日","0501*劳动节","0504*青年节","0512*护士节","0601*儿童节","0628*老Y发布纪念日","0701*建党节 香港回归纪念",
    148 "0801*建军节","0808*父亲节","0909*毛主席逝世纪念","0910*教师节","0928*孔子诞辰","1001*国庆节",
    149 "1006*老人节","1024*联合国日","1112*孙中山诞辰","1220*澳门回归纪念","1225*圣诞节","1226*毛主席诞辰")
    150 
    151   var sDObj = new Date(SY,SM,SD);
    152   var lDObj = new Lunar(sDObj);
    153   var lDPOS = new Array(3)
    154   var festival='',solarTerms='',solarFestival='',lunarFestival='',tmp1,tmp2;
    155   //农历节日 
    156   for(i in lFtv)
    157   if(lFtv[i].match(/^(d{2})(.{2})([s*])(.+)$/)) {
    158    tmp1=Number(RegExp.$1)-lDObj.month
    159    tmp2=Number(RegExp.$2)-lDObj.day
    160    if(tmp1==0 && tmp2==0) lunarFestival=RegExp.$4 
    161   }
    162   //国历节日
    163   for(i in sFtv)
    164   if(sFtv[i].match(/^(d{2})(d{2})([s*])(.+)$/)){
    165    tmp1=Number(RegExp.$1)-(SM+1)
    166    tmp2=Number(RegExp.$2)-SD
    167    if(tmp1==0 && tmp2==0) solarFestival = RegExp.$4 
    168   }
    169   //节气
    170   tmp1 = new Date((31556925974.7*(SY-1900)+sTermInfo[SM*2+1]*60000)+Date.UTC(1900,0,6,2,5))
    171   tmp2 = tmp1.getUTCDate()
    172   if (tmp2==SD) solarTerms = solarTerm[SM*2+1]  
    173   tmp1 = new Date((31556925974.7*(SY-1900)+sTermInfo[SM*2]*60000)+Date.UTC(1900,0,6,2,5))
    174   tmp2= tmp1.getUTCDate()
    175   if (tmp2==SD) solarTerms = solarTerm[SM*2] 
    176 
    177   if(solarTerms == '' && solarFestival == '' && lunarFestival == '')
    178     festival = '';
    179   else
    180     festival = '<font color="#FF0000" style="font-size:9pt;">'+solarTerms + ' ' + solarFestival + ' ' + lunarFestival+'</font>';
    181          
    182   var cl = '<font color="" style="font-size:9pt;">';
    183   return(cl+festival+'</font>');
    184  }
    185  function setCalendar(){
    186  
    187     document.write(YYMMDD()+'&nbsp;'+weekday() + "&nbsp;");
    188     //document.write(" <span style="font-size:9pt;color:">农历:</span>" );
    189     document.write(" " + solarDay2());
    190     document.write(" " + solarDay3());
    191     //document.write(" " + solarDay1());
    192  }
    193 
    194  setCalendar();
    195 //-->
    196 
    197 //返回顶部调用代码

    把上面代码存为data.js直接引入即可

  • 相关阅读:
    声明对象指针,调用构造、析构函数的多种情况
    [C++ STL] 常用算法总结
    [C++ STL] map使用详解
    [C++ STL] set使用详解
    [C++ STL] list使用详解
    [C++ STL] deque使用详解
    Servlet课程0424(一) 通过实现Servlet接口来开发Servlet
    CSS盒子模型
    Spring学习之第一个hello world程序
    Java基础面试题
  • 原文地址:https://www.cnblogs.com/php-qiuwei/p/QQ1805843351.html
Copyright © 2011-2022 走看看