Repeater中使用倒计时

时间:2023-03-09 07:24:55
Repeater中使用倒计时
<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 = ; i < Elements.length; i++) {
var el = Elements[i];
if (el.id.indexOf('lblTime') >= ) { 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[]); /*到倒计时的日期*/
var H1 = parseInt(arr[]); /*到倒计时的日期指定的几点*/
var M1 = parseInt(arr[]); /*到倒计时的日期几份*/
var S1 = parseInt(arr[]); /*到倒计时的日期几秒*/ ms = Math.floor((day1 - now) / ) /*到指定的那天0点0分0秒所剩下秒数*/ H2 = Math.floor(ms / )
M2 = Math.floor((ms - H2 * ) / )
S2 = ms - H2 * - M2 * + S = S2 + S1
M = M1 + M2
H = H2 + H1 if (S > ) M = M + ;
if (S > ) S = S - ;
if (M > ) H = H + ;
if (M > ) M = M - ;
if (H >= ) {
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[]); /*到倒计时的日期*/
var H1 = parseInt(arr[]); /*到倒计时的日期指定的几点*/
var M1 = parseInt(arr[]); /*到倒计时的日期几份*/
var S1 = parseInt(arr[]); /*到倒计时的日期几秒*/ ms = Math.floor((day1 - now) / ) /*到指定的那天0点0分0秒所剩下秒数*/ H2 = Math.floor(ms / )
M2 = Math.floor((ms - H2 * ) / )
S2 = ms - H2 * - M2 * + S = S2 + S1
M = M1 + M2
H = H2 + H1 if (S > ) M = M + ;
if (S > ) S = S - ;
if (M > ) H = H + ;
if (M > ) M = M - ;
if (H >= ) {
time2 = "抢购商品剩余支付时间:<br/>" + H + "小时" + M + "分" + S + "秒<br/>";
$("#" + id).html(time2);
var timer = setTimeout("countdown('" + source + "','" + id + "')", );
}
else {
$("#" + id).hide();
}
}

后台部分:

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

/// <summary>
/// 设置前台日期格式显示
/// </summary>
/// <param name="string">结束日期时间</param>
/// <returns></returns>
public string FormatDateString(string dateString, SecondDie model)
{
string result = ""; if (model.SencondNum > )
{
string EndDate = DateTime.Parse(dateString).ToString("yyyy-MM-dd HH:mm:ss"); string year = EndDate.Substring(, );
string month = EndDate.Substring(, );
string day = EndDate.Substring(, ); string hour = EndDate.Substring(, );
string minute = EndDate.Substring(, );
string second = EndDate.Substring(, ); result = month + "/" + day + "/" + year + "," + hour + "," + minute + "," + second;
} return result;
}

OK! 至此结束