天天看點

當月的所有周日 倒計時顯示當年剩下的天時分秒 公曆轉農曆(.net)

<script type="text/javascript">
var year = new Date().getFullYear();
var month = new Date().getMonth();
var result = [];
for(var i = 1; i <= 31; i++){
    var weekday = new Date(year, month, i).getDay();
    if(weekday == 0 || weekday == 6 ){
        result.push(i);
    }
}
document.write((month + 1) + "月:" + result.join(","));
</script>



// 輸入框如果輸入數字自動三位三位加逗号
<script type="text/javascript">
function onKeyPrice(t) 
{ 
    var stmp = ""; 
    if(t.value==stmp)
    {
        return; 
    }
    var ms = t.value.replace(/[^\d\.]/g,"").replace(/(\.\d{2}).+$/,"$1").replace(/^0+([1-9])/,"$1").replace(/^0+$/,"0"); 
    var txt = ms.split("."); 
    while(/\d{4}(,|$)/.test(txt[0])) 
    {
       txt[0] = txt[0].replace(/(\d)(\d{3}(,|$))/,"$1,$2"); 
    }
    t.value = stmp = txt[0]+(txt.length>1?"."+txt[1]:""); 
} 
</script>
<input name="" type="text" onkeyup="onKeyPrice(this);" />
<asp:TextBox ID="TextBox1" runat="server" onkeyup="onKeyPrice(this);"></asp:TextBox>




//商品購買 倒計時
商品A   28天8小時6分53秒
商品b   28天8小時6分53秒
商品C   28天8小時6分53秒
商品D   28天8小時6分53秒

<div id='divs'>
<div>商品A   <span> </span> </div><br>
<div>商品b   <span> </span> </div><br>
<div>商品C   <span> </span> </div><br>
<div>商品D   <span> </span> </div></div>
<div id='CountMsg'> </div>

<script language="JavaScript">
function GetRTime(){
var EndTime= new Date("10/11/2009"); //截止時間(月 日 年)
var NowTime = new Date();
var nMS =EndTime.getTime() - NowTime.getTime();
var nD =Math.floor(nMS/(1000 * 60 * 60 * 24));
var nH=Math.floor(nMS/(1000*60*60)) % 24;
var nM=Math.floor(nMS/(1000*60)) % 60;
var nS=Math.floor(nMS/1000) % 60;
var Remain=document.getElementById("divs").getElementsByTagName('SPAN');
if(nD>= 0){
for(var i=0;i <Remain.length;i++){
Remain[i].innerHTML=nD+'天'+nH+'小時'+nM+'分'+nS+'秒';
}
}
else {
document.getElementById("CountMsg").innerHTML="時已過!";

}
setInterval("GetRTime()",1000);
}
window.onload=GetRTime;
</script>      

拍賣網

  剩餘時間:

<span id='Countdown456'></span> <br />
                          <script>
                              var liftoffTime456 = new Date(2010,5-1,28,17,0,0);
                              var serverdate = new Date(2010,5-1,26,16,43,56);
                                var localdate = new Date();
                                var jtime = localdate-serverdate;
                                liftoffTime456.setUTCSeconds(liftoffTime456.getUTCSeconds()+Math.round(jtime/1000));
                              $(function() {
                              $('#Countdown456').countdown({alwaysExpire: true, until: liftoffTime456, format: 'DHMS', timezone: +8, onExpiry:function(){ liftOff('456')} });
                              });
                          </script>      

一道百度JS大面試題

題目在網頁裡倒計時顯示當年剩下的天時分秒,格式:XX年還剩下X天X時X分X秒

當月的所有周日 倒計時顯示當年剩下的天時分秒 公曆轉農曆(.net)
當月的所有周日 倒計時顯示當年剩下的天時分秒 公曆轉農曆(.net)

代碼

//時間倒數
//parentID = "#TeamTime"
//<span id="TeamTime"><em>20</em>天<em>7</em>小時<em>3</em>分<em>2</em>秒</span>
function getLeaveTime(parentID) {
    $.each(parentID, function(i, n) {
        getLeavaSingleTime(n); 
        //alert(n);
    });
    return;
}

function getLeavaSingleTime(parentID) {

    var tid = parentID + ">em";

    if ($(tid).text()=='') {
        return;
    }
    else {
        var sec = $(tid).eq(3).text();
        var min = $(tid).eq(2).text();
        var hou = $(tid).eq(1).text();
        var day = $(tid).eq(0).text();
        if (Number(sec) > 0)
            $(tid).eq(3).text(--sec);
        else {
            $(tid).eq(3).text(59);
            if (Number(min) > 0)
                $(tid).eq(2).text(--min);
            else {
                $(tid).eq(2).text(59);
                if (Number(hou) > 0)
                    $(tid).eq(1).text(--hou);
                else {
                    $(tid).eq(1).text(23);
                    if (Number(day) > 0)
                        $(tid).eq(0).text(--day);
                    else {
                        $(parentID).text("已結束");
                        //clearInterval(time);
                    }
                }
            }
        }
    }

}

function calculateCountdown() {
    //The current date and time 
    var todaysDate = new Date();      

    /*The date and time of the target date in Greenwich Mean Time (year, month-1, day of month, hours in 24-hour notation, minutes, seconds, milliseconds). The "month-1" can trip you up if you're not carefully. So, for example, May is 4.*/

    var targetDate = new Date(2008, 10, 25, 13, 0, 0, 0);

    //var str = "2008/10/22 09:21:00";

    /*The getTimezoneOffset function returns the number of minutes west of GMT the browser is. For example, a browser in the New York EST timezone would be 300 minutes off of GMT. NOTE: does not factor in Daylight Saving Time.*/

var timezoneOffset = (todaysDate.getTimezoneOffset() * 60) * 1000;

    /*Factor in the time zone of the web browser before determine the time between now and the conference start time.*/
    var timeDifference = (targetDate - timezoneOffset) - todaysDate;

    //Now calculate the days, hours, minutes, and seconds from the time difference 
    var countDown = new Array(4);
    countDown[0] = Math.floor((((timeDifference / 1000) / 60) / 60) / 24);
    countDown[1] = Math.floor((((timeDifference / 1000) / 60) / 60) % 24);
    countDown[2] = Math.floor(((timeDifference / 1000) / 60) % 60);
    countDown[3] = Math.floor((timeDifference / 1000) % 60);

    //Output the result
    return countDown;
} //end of the calculateCountdown function      

C#(ASP.NET)公曆轉農曆的簡單方法

static string SolarToChineseLunisolarDate(DateTime solarDateTime)
{
    System.Globalization.ChineseLunisolarCalendar cal = new System.Globalization.ChineseLunisolarCalendar();

    int year = cal.GetYear(solarDateTime);
    int month = cal.GetMonth(solarDateTime);
    int day = cal.GetDayOfMonth(solarDateTime);
    int leapMonth = cal.GetLeapMonth(year);
    return string.Format("農曆{0}{1}({2})年{3}{4}月{5}{6}"
                        , "甲乙丙丁戊己庚辛壬癸"[(year - 4) % 10]
                        , "子醜寅卯辰巳午未申酉戌亥"[(year - 4) % 12]
                        , "鼠牛虎兔龍蛇馬羊猴雞狗豬"[(year - 4) % 12]
                        , month == leapMonth ? "閏" : ""
                        , "無正二三四五六七八九十冬臘"[leapMonth > 0 && leapMonth <= month ? month - 1 : month]
                        , "初十廿三"[day / 10]
                        , "日一二三四五六七八九"[day % 10]
                        );
}      

使用的方法非常簡單:

string 農曆 = SolarToChineseLunisolarDate(DateTime.Today);

繼續閱讀