/    Sign up×
Community /Pin to ProfileBookmark

Shortcut for new Date()

Is there a shortcut to define a new Date() object? Similar to {} for new Object() and [] for new Array()? Thanks…

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@mrhooMay 30.2007 — You can't have an empty Date object, the way you can instantiate an empty array or object.

There is no date, in javascript, that is not a [B]particular [/B]date.

new Date() is as short as it gets, and as long as it needs to be, because you can define any possible instance of a Date object with its arguments and methods.
Copy linkTweet thisAlerts:
@VicauthorMay 30.2007 — Thanks. Just one more question... if I initiate a new Date() (which is defaulted to the current date), how can I subseqeuntly fill the date from a string? For example, I can do x = new Date("1 Jun 2007") but I *cannot* do x = new Date(); x.setDate("1 Jun 2007")...
Copy linkTweet thisAlerts:
@mrhooMay 30.2007 — If your string is formatted for a date use Date.parse-

var x = new Date(Date.parse("1 Jun 2007"));
×

Success!

Help @Vic spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...