2012-11-22 72 views
1
function validateDate() 
      { 
       var dateDifference; 
       pickedDate = Date.parse(txtDate.value.replace(/-/g, " ")); 
       todaysDate = new Date(); 
       todaysDate.setHours(0, 0, 0, 0); 
       dateDifference = Math.abs(Number(todaysDate) - pickedDate); 
       //7 Days=604800000ms// 
       if (dateDifference > 604800000) 
       { 
         alert("Appointment can be fixed for next seven days only from current day.");       
        return false; 
       } 
       else 
       { 
        return true; 
       } 
      } 

I m getting server side date from c# in this format 2012-11-22 12:53:23 
now i have to convert server datetime to millisecond for checking 7 days difference 

***txtDate.value=22-Nov-2012*** 
+0

實際在頁面加載的母版頁上我設置了datetime和acess那個變量serverDateTime遍歷所有頁面 – lax

回答

0

試試這個:

var time = '2012-11-22 12:53:23'; // this value is what you get from server 

var a=time.split(' '); 
var d=a[0].split('-'); 
var t=a[1].split(':'); 

var date = new Date(d[0],d[1],d[2],t[0],t[1],t[2]); 

var millisecs = date.getTime(); // server time in milliseconds 

var todayTime = (new Date()).getTime(); 

var diff = todayTime - millisecs; // work on this 

希望這有助於。

+0

我已經更新了queing – lax

+0

var todayTime =(new Date())。getTime(); pushpesh這是從客戶端我想從服務器端獲得時間 – lax

+0

哦!我誤解了這一點。但是,通過在加載頁面時將服務器時間傳遞給'todayTime',可以輕鬆獲得該值。 Javascript不能直接訪問服務器屬性。 –