C#结合JavaScript实现秒杀倒计时的方法
程序员文章站
2023-12-12 14:51:52
本文实例讲述了c#结合javascript实现秒杀倒计时的方法。分享给大家供大家参考。具体如下:
最近做个秒杀活动,要用到倒计时。要求每周三上午10:00开始倒计时...
本文实例讲述了c#结合javascript实现秒杀倒计时的方法。分享给大家供大家参考。具体如下:
最近做个秒杀活动,要用到倒计时。要求每周三上午10:00开始倒计时
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); } }); });
希望本文所述对大家的c#程序设计有所帮助。