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?
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});
精彩评论