C#聯合JavaScript完成秒殺倒計時的辦法。本站提示廣大學習愛好者:(C#聯合JavaScript完成秒殺倒計時的辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是C#聯合JavaScript完成秒殺倒計時的辦法正文
本文實例講述了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#法式設計有所贊助。