techques
asked on
why cannot calculate 2 date time's difference?
Hi
I have the following js and it can show
var dthen = 2009-02-28 13:00:00
var dnow = 2009-02-18 13:00:00
But, it shows NaN of the alert (ddiff) and (gsecs).
What's wrong with the code?
I use aspx, vc#.
I have the following js and it can show
var dthen = 2009-02-28 13:00:00
var dnow = 2009-02-18 13:00:00
But, it shows NaN of the alert (ddiff) and (gsecs).
What's wrong with the code?
I use aspx, vc#.
StartCountDown("10","2009-02-28 13:00:00", "<%= SystemDateTime %>")
function StartCountDown(myDiv,myTargetDate,sysDateTime)
{
var dthen = new Date(myTargetDate); //2009-02-28 13:00:00
var dnow = new Date(sysDateTime); //2009-02-18 13:00:00
ddiff = new Date(dthen-dnow);
window.alert(ddiff);
gsecs = Math.floor(ddiff.valueOf()/1000);
window.alert(gsecs);
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
In javascript create a Date object with this:
dateObj = new Date(year, month, date[, hours[, minutes[, seconds[,ms]]]])
the code you are using is actually this:
new Date('2009/02/28 13:00:00');
whioch does not seem to create a data object in javascript
dateObj = new Date(year, month, date[, hours[, minutes[, seconds[,ms]]]])
the code you are using is actually this:
new Date('2009/02/28 13:00:00');
whioch does not seem to create a data object in javascript
Try this
StartCountDown("10",'2009/
function StartCountDown(myDiv,myTar
{
var dthen = new Date(myTargetDate); //2009-02-28 13:00:00
var dnow = new Date(sysDateTime); //2009-02-18 13:00:00
ddiff = new Date(dthen-dnow);
window.alert(ddiff);
gsecs = Math.floor(ddiff.valueOf()
window.alert(gsecs);
}