前端
var allTime = Math.round(data.RemainTime)
var Hours = Math.floor(allTime / (60 * 60));var allMunite = Math.floor(allTime % (60 * 60));
var munite = Math.floor(allMunite / 60);
var second = Math.floor((allMunite % 60));
var currentTime = (Hours < 10 ? '0' + Hours : Hours) + ':' + (munite < 10 ? '0' + munite : munite) + ':' + (second < 10 ? '0' + second : second);
$('.spanTimeshow').html(currentTime)
refreshtime($('.spanTimeshow'), data.RemainTime)
function refreshtime(obj, spantime) {
//clearInterval(setInt);
var setInt=setInterval(function () {
//播放时间、总时间
var allTime1 = Math.round(spantime)
var Hours1 = Math.floor(allTime1 / (60 * 60));
var allMunite1 = Math.floor(allTime1 % (60 * 60));
var munite1 = Math.floor(allMunite1 / 60);
var second1 = Math.floor((allMunite1 % 60));
var currentTime1 = (Hours1 < 10 ? '0' + Hours1 : Hours1) + ':' + (munite1 < 10 ? '0' + munite1 : munite1) + ':' + (second1 < 10 ? '0' + second1 : second1);
$(obj).html(currentTime1)
if (spantime<=0)
{
$('.groupsh').addClass('hide');
clearInterval(setInt);
}
spantime--;
}, 1000)
}
后端
public void GetRroupList(HttpContext context)
{
string json="";
int productId = Globals.RequestFormNum("productId");
DataTable dt=OrderHelper.GetGroupList(productId);
for (int i = 0; i < dt.Rows.Count;i++ )
{
DateTime dtnow = Convert.ToDateTime(DateTime.Now.ToLocalTime());
DateTime dtend = Convert.ToDateTime(dt.Rows[i]["GroupEDate"]);
TimeSpan ts = dtend.Subtract(dtnow); //时间差
json += "{\"CategoryId\":\"" + dt.Rows[i]["CategoryId"] + "\",\"GroupUser\":\"" + dt.Rows[i]["GroupUser"] + "\",\"RemainTime\":\"" + ts.TotalSeconds + "\",\"sy\":\"" + dt.Rows[i]["sy"] + "\"},";
}
if (!string.IsNullOrEmpty(json))
{
json = json.Substring(0, json.Length - 1);
}
json = "[" + json + "]";
context.Response.Write(json);
}