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***
问问题
239 次
1 回答
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
希望这可以帮助。
于 2012-11-22T09:42:31.153 回答