I have a strange issue in my project. I am trying to dynamically insert parameters to Date object constructor. Here is my code:
from += fromYear + "," + fromMonth + "," + fromDay + "," + fromHour + "," + fromMinute;
to += toYear + "," + toMonth + "," + toDay + "," + toHour + "," + toMinute;
console.log(from); //here is log value: 2012,8,25,9,22
console.log(to); //another log: 2012,8,25,9,52
//Creating object
var fromtime = new Date(from);
var totime = new Date(to);
When I am trying to alert the date object (totime or fromtime) there is an error: Invalid Date. I have no idea how to pass it. Could you help me?
I tried this:
Creating Date Object JS
In your example
fromis a comma delimited string, not a series of discreet variables which is what theDateconstructor requires as arguments:(Months are 0 based so you may want to add 1)