Ian Boyd
Ian Boyd

Reputation: 256741

Does Javascript have Java's Calendar helper class?

i'm trying to use the Java version of:

Date d = new Date(2010, Calendar.AUGUST, 28);

but in Javascript:

var d = new Date(2010, ???, 28);

i cannot find a helper class that contains month constants? Does the Java helper Calendar class exist in Javascript?

Upvotes: 1

Views: 3885

Answers (1)

gimel
gimel

Reputation: 86372

Javascript is not Java. Fortunately, there are libraries like datejs.

Datejs is an open-source JavaScript Date Library.

Comprehensive, yet simple, stealthy and fast. Datejs has passed all trials and is ready to strike. Datejs doesn’t just parse strings, it slices them cleanly in two.

For an example, see the set() method:

set

.set ( Object config ) : Date

Set the value of year, month, day, hour, minute, second, millisecond of date instance using given configuration object.

// returns Jul 15 2008 18:45:30
Date.today().set({millisecond: 500, second: 30, minute: 45, hour: 18, day: 15, month: 6, year: 2008});

Upvotes: 3

Related Questions