• 欢迎访问开心洋葱网站,在线教程,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站,欢迎加入开心洋葱 QQ群
  • 为方便开心洋葱网用户,开心洋葱官网已经开启复制功能!
  • 欢迎访问开心洋葱网站,手机也能访问哦~欢迎加入开心洋葱多维思维学习平台 QQ群
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏开心洋葱吧~~~~~~~~~~~~~!
  • 由于近期流量激增,小站的ECS没能经的起亲们的访问,本站依然没有盈利,如果各位看如果觉着文字不错,还请看官给小站打个赏~~~~~~~~~~~~~!

C#结合JavaScript实现秒杀倒计时代码

JavaScript 水墨上仙 2920次浏览

C#结合JavaScript实现秒杀倒计时代码

最近做个秒杀活动,要用到倒计时。要求每周三上午10:00开始倒计时

转自:http://blog.csdn.net/wanglong7505

private string Dtime()  
    {  
        byte tempB = (byte)DateTime.Now.DayOfWeek;  
        byte dayByte = (byte)DayOfWeek.Wednesday;  
        DateTime wednesdayNow = DateTime.Now.AddDays(dayByte - tempB);//本星期三  
        DateTime returnTime = new DateTime ();  
        if (DateTime.Now.DayOfWeek < wednesdayNow.DayOfWeek)  
        {  
            //当前星期小于本星期三  获取本周星期三  
           returnTime =  new DateTime(wednesdayNow.Year, wednesdayNow.Month, wednesdayNow.Day, 10, 0, 0);  
        }  
        else  
        {  
            //当前星期大于本星期三  获取下周星期三  
            DateTime nextWednesday = wednesdayNow.AddDays(7);//下周三  
            returnTime = new DateTime(nextWednesday.Year, nextWednesday.Month, nextWednesday.Day, 10, 0, 0);  
        }  
        return returnTime.ToString()  

这个方法可以得到每周三的时间,然后用js对该时间进行倒计时


$(document).ready(function() {
    $('body').everyTime('1s', function() {
var nowDate = new Date();
        var endDate = new Date($("#sp_next").html().replace(//-/g, "//"));//这个时间是上个方法返回的时间
var timeold = endDate.getTime() - nowDate.getTime();
        var sectimeold = timeold / 1000
        var secondsold = Math.floor(sectimeold);
        var msPerDay = 24 * 60 * 60 * 1000
        var e_daysold = timeold / msPerDay
        var daysold = Math.floor(e_daysold);
        var e_hrsold = (e_daysold - daysold) * 24 + (daysold * 24);
        var hrsold = Math.floor(e_hrsold);
        var e_minsold = (e_hrsold - hrsold) * 60;
        var minsold = Math.floor((e_hrsold - hrsold) * 60);
        var seconds = Math.floor((e_minsold - minsold) * 60);
        if (hrsold > 0 && hrsold < 10) { hrsold = "0" + hrsold; }
        if (minsold < 10) { minsold = "0" + minsold; }
        if (seconds < 10) { seconds = "0" + seconds; }
        if (hrsold < 0) {
            $(".seckill_time").html("0");
            $(".seckill_minute").html("0");
            $(".seckill_second").html("0");
        } else {
            $(".seckill_time").html("").html(hrsold);
            $(".seckill_minute").html("").html(minsold);
            $(".seckill_second").html("").html(seconds);
        }
    });
});


喜欢 (0)
加载中……