ShaggyMoose wrote:
I want to apply an array of arguments against the Date constructor to
set a specific date/time. I can't seem to find the syntax to do this.
Using eval to expand the array into seperate arguments for "new" feels
dirty. Is this possible?
eg. Date.apply(?, myArgs);
It is possible, like
Date.apply(null, myArgs);
but the outcome is not what you want. Date() when not called as a
constructor returns a string representing the current date and time,
no matter the arguments.
What you can do is something like the following:
Date.prototype.setDateTime = function(o)
{
for (var p in o)
{
var m = "set" + p.charAt(0).toUpperCase() + p.substr(1);
if (typeof this[m] == "function")
{
this[m](o[p]);
}
}
};
var firstContact = new Date();
firstContact.setDateTime({
year: 2063, month: 4, date: 5, hours: 11, minutes: 0, seconds: 0,
milliseconds: 0
});
PointedEars