473,394 Members | 1,671 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Using apply with Date constructor?

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);
Feb 20 '08 #1
2 3091
SAM
ShaggyMoose a écrit :
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);
function dateConstruct(myArgs) {
myArgs = "'"+myArgs.split(',').join('\',\'')+"'";
return new Date(myArgs);
}

does that could work ? no lo sè.

--
sm
Feb 20 '08 #2
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
Feb 23 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Sandros | last post by:
Background: I'm collecting usability statistics for a group of applications. Each count has the following attributes: date, application, major heading, minor heading, count. My intent is to pull...
28
by: Daniel | last post by:
Hello =) I have an object which contains a method that should execute every x ms. I can use setInterval inside the object construct like this - self.setInterval('ObjectName.methodName()',...
9
by: Matt Eberts | last post by:
Sorry, bad title. Anyway, is there a way to pass the arguments to an object instantiated via a constructor using the arguments object and have it expanded, so to speak, so that it doesn't appear as...
6
by: Alex Fitzpatrick | last post by:
Just by way of introduction, I'm currently the principal developer and maintainer of the a JavaScript editor plug-in for Eclipse. https://sourceforge.net/projects/jseditor/ The plug-in as it...
9
by: Guy | last post by:
I have extended the datetimepicker control to incorporate a ReadOnly property. I have used the new keyword to implement my own version of the value property, so that if readonly == true then it...
1
by: Prasad Karunakaran | last post by:
I am using the C# DirectoryEntry class to retrieve the Properties of an user object in the Active Directory. I need to get the First Name and Last Name as properties. I know it is not supported...
14
by: Steve Teeples | last post by:
I don't understand why I cannot use a property to modify data within a struct. Can someone tell me why I get the error "Cannot modify the return value of "myData.TheData" because it is not a...
3
by: binary_sunset | last post by:
Okay... so this may be all to obvious to all except myself, but I am having some difficulty with XML output from Adobe InDesign. Each separate article in my publication is tagged as an article,...
23
by: Steven TK | last post by:
Hi everyone, I wonder who can help me on the filter the Start Date and End Date. I still cannot manage to filter it. Eg. When the user click the StartDate(comboBox as 16/7/07), the Start...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.