码迷,mamicode.com
首页 > 其他好文 > 详细

Repeater中使用倒计时

时间:2014-08-05 13:47:59      阅读:255      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   使用   os   io   for   ar   

<asp:Label ID="lblTime" runat="server" Text=<%# FormatDateString(Eval("OrderDate").ToString(),(Orders)Container.DataItem) %>></asp:Label>                                      

JS部分:

/*将列表控件中的"id=lblTime"的控件html转换成页面效果*/
    function clockon() {

        var Elements = document.getElementsByTagName("span");
        for (i = 0; i < Elements.length; i++) {
            var el = Elements[i];
            if (el.id.indexOf(lblTime) >= 0) {

                var id = el.id;
                var source = $("#" + id).html();

                if (source != "") {
                    var arr = new Array();
                    arr = source.split(",");

                    var now = new Date();
                    var year = now.getFullYear(); //getFullYear getYear
                    var month = now.getMonth();
                    var date = now.getDate();
                    var day = now.getDay();
                    var hour = now.getHours();
                    var minu = now.getMinutes();
                    var sec = now.getSeconds();

                    var day1 = new Date(arr[0]); /*到倒计时的日期*/
                    var H1 = parseInt(arr[1]); /*到倒计时的日期指定的几点*/
                    var M1 = parseInt(arr[2]); /*到倒计时的日期几份*/
                    var S1 = parseInt(arr[3]); /*到倒计时的日期几秒*/

                    ms = Math.floor((day1 - now) / 1000) /*到指定的那天0点0分0秒所剩下秒数*/

                    H2 = Math.floor(ms / 3600)
                    M2 = Math.floor((ms - H2 * 3600) / 60)
                    S2 = ms - H2 * 3600 - M2 * 60 + 1

                    S = S2 + S1
                    M = M1 + M2
                    H = H2 + H1

                    if (S > 59) M = M + 1;
                    if (S > 59) S = S - 60;
                    if (M > 59) H = H + 1;
                    if (M > 59) M = M - 60;
                    if (H >= 0) {
                        time2 = "抢购商品剩余支付时间:<br/>" + H + "小时" + M + "" + S + "秒<br/>";
                        $("#" + id).html(time2);
                        //开始倒计时
                        countdown(source, id);
                    }
                    else {
                        $("#" + id).hide();
                        $("#" + id).html("活动已结束");
                    }
                }
                else {
                    $("#" + id).hide();
                    $("#" + id).html("活动已结束");
                }
            }
        }
    }
    //source:到期时间格式(MM/DD/YYYY/,HH,MM,SS);id:控件ID
    function countdown(source, id) {
        var arr = new Array();
        arr = source.split(",");

        var now = new Date();
        var year = now.getFullYear(); //getFullYear getYear
        var month = now.getMonth();
        var date = now.getDate();
        var day = now.getDay();
        var hour = now.getHours();
        var minu = now.getMinutes();
        var sec = now.getSeconds();

        var day1 = new Date(arr[0]); /*到倒计时的日期*/
        var H1 = parseInt(arr[1]); /*到倒计时的日期指定的几点*/
        var M1 = parseInt(arr[2]); /*到倒计时的日期几份*/
        var S1 = parseInt(arr[3]); /*到倒计时的日期几秒*/

        ms = Math.floor((day1 - now) / 1000) /*到指定的那天0点0分0秒所剩下秒数*/

        H2 = Math.floor(ms / 3600)
        M2 = Math.floor((ms - H2 * 3600) / 60)
        S2 = ms - H2 * 3600 - M2 * 60 + 1

        S = S2 + S1
        M = M1 + M2
        H = H2 + H1

        if (S > 59) M = M + 1;
        if (S > 59) S = S - 60;
        if (M > 59) H = H + 1;
        if (M > 59) M = M - 60;
        if (H >= 0) {
            time2 = "抢购商品剩余支付时间:<br/>" + H + "小时" + M + "" + S + "秒<br/>";
            $("#" + id).html(time2);
            var timer = setTimeout("countdown(‘" + source + "‘,‘" + id + "‘)", 200);
        }
        else {
            $("#" + id).hide();
        }
    }

后台部分:

 需要传入一个结束时间到前台

/// <summary>
    /// 设置前台日期格式显示
    /// </summary>
    /// <param name="string">结束日期时间</param>
    /// <returns></returns>
    public string FormatDateString(string dateString, SecondDie model)
    {
        string result = "";

        if (model.SencondNum > 0)
        {
            string EndDate = DateTime.Parse(dateString).ToString("yyyy-MM-dd HH:mm:ss");

            string year = EndDate.Substring(0, 4);
            string month = EndDate.Substring(5, 2);
            string day = EndDate.Substring(8, 2);

            string hour = EndDate.Substring(11, 2);
            string minute = EndDate.Substring(14, 2);
            string second = EndDate.Substring(17, 2);

            result = month + "/" + day + "/" + year + "," + hour + "," + minute + "," + second;
        }

        return result;
    }

OK! 至此结束

 

Repeater中使用倒计时,布布扣,bubuko.com

Repeater中使用倒计时

标签:style   blog   color   使用   os   io   for   ar   

原文地址:http://www.cnblogs.com/mandalaluo/p/3891882.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!