1
我嘗試設置結束時間(過期/倒計時)如何在ASp.net閱讀日期時間從數據庫中使用Java腳本
<p id="demo"></p>
<script>
// Set the date we're counting down to
var countDownDate = new Date("Jan 5, 2018 15:37:25").getTime();
// Update the count down every 1 second
var x = setInterval(function() {
// Get todays date and time
var now = new Date().getTime();
// Find the distance between now an the count down date
var distance = countDownDate - now;
// Time calculations for days, hours, minutes and seconds
var days = Math.floor(distance/(1000 * 60 * 60 * 24));
var hours = Math.floor((distance % (1000 * 60 * 60 * 24))/(1000 * 60 * 60));
var minutes = Math.floor((distance % (1000 * 60 * 60))/(1000 * 60));
var seconds = Math.floor((distance % (1000 * 60))/1000);
// Output the result in an element with id="demo"
document.getElementById("demo").innerHTML = days + "d " + hours + "h "
+ minutes + "m " + seconds + "s ";
// If the count down is over, write some text
if (distance < 0) {
clearInterval(x);
document.getElementById("demo").innerHTML = "EXPIRED";
}
}, 1000);
</script>
這段代碼的工作,但日期是靜態 我需要改變var countDownDate = new Date("Jan 5, 2018 15:37:25").getTime();
從重視數據庫 怎麼辦?
在asp.net和entitiyframework
兩種方式浮現在腦海中:1)檢索使用AJAX 2)綁定值從DB值頁面加載時的隱藏輸入。另請參閱http://stackoverflow.com/questions/1244094/converting-json-results-to-a-date關於如何將AJAX響應轉換爲JS Date對象。 –
你解決了這個問題嗎? –