# .net倒计时

0
[已解决问题] 解决于 2010-11-19 15:34

°潶、緤° | 初学一级 | 园豆：17

0

```客户端<p id="timeCounter">       <span class="day"><em>0</em>天</span><br/><span class="hour"><em>0</em>小时</span>       <span class="minute"><em>0</em>分</span><span class="second"><em>0</em>秒</span> </p>

var lefttime = <%=LeftTime%>; var begintime = 0;var updateInterval = 60000;\$(function () {     begintime = new Date().getTime();    ShowTimeCounter(); }) function ShowTimeCounter() {    var nowtime = new Date().getTime();    var SysSecond = Math.round(lefttime - (nowtime - begintime) / 1000);    if (SysSecond < 0) {        clearTimeout(T1);        \$(".buy_success").html("<p><span>报名时间已结束</span></p>");        return;    }    var day = SysSecond / (24 * 60 * 60)    var day = Math.floor(day);                         //相差的总天数       SysSecond = SysSecond - day * 24 * 60 * 60;     //抛去相差天数后的秒数    var hour = (SysSecond / (60 * 60));    var hour = Math.floor(hour);                     //相差的小时数    var SysSecond = SysSecond - hour * 60 * 60;      //抛去相差小时后的秒数    var min = SysSecond / 60;    var min = Math.floor(min);                         //相差的分钟数    var SysSecond = SysSecond - min * 60;             //抛去相差分钟后的秒数    var sec = SysSecond;    day = (day + "").length == 1 ? "0" + day : day;    hour = (hour + "").length == 1 ? "0" + hour : hour;    min = (min + "").length == 1 ? "0" + min : min;    sec = (sec + "").length == 1 ? "0" + sec : sec;    \$("#timeCounter").html("<span class=\"day\"><em>" + day        + "</em>天</span><span class=\"hour\"><em>" + hour        + "</em>小时</span><br/><span class=\"minute\"><em>" + min        + "</em>分</span><span class=\"second\"><em>" + sec        + "</em>秒</span>");    var T1 = setTimeout(ShowTimeCounter, 1000);}
```

`服务器端double m_LeftTime = Utilities.DateDiff(EndTime, DateTime.Now).TotalSeconds;LeftTime = m_LeftTime.ToString("0");/// <summary>/// 计算两个日期的时间间隔/// </summary>/// <param name="DateTime1">第一个日期和时间</param>/// <param name="DateTime2">第二个日期和时间</param>/// <returns></returns>public static TimeSpan DateDiff(DateTime DateTime1, DateTime DateTime2){    TimeSpan ts1 = new TimeSpan(DateTime1.Ticks);    TimeSpan ts2 = new TimeSpan(DateTime2.Ticks);    TimeSpan ts = ts1.Subtract(ts2);    return ts;}`

0

settimeout?

0

like%'远远'% | 园豆：635 (小虾三级) | 2010-11-12 11:47
0

1.倒计时的效果你可以用js实现，网上有很多的例子。

2.抢购的问题个人觉得你不用想的太复杂，用户点击抢购按钮的时候，你就判断一下数据库的“限时”和当前的系统时间。

您需要登录以后才能回答，未注册用户请先注册