-
Notifications
You must be signed in to change notification settings - Fork 79
API Documentation
Static methods do not require a specific date object instance (i.e. var x = new Date();
) to be used - they work with the built-in Date object as part of its prototype.
Gets a date that is set to the current date. The time is set to the start of the day (00:00 or 12:00 AM).
Date.today();
None
Date Object - The current date.
Compares the first date to the second date and returns an number indication of their relative values. -1 = this is less than date. 0 = values are equal. 1 = this is greater than date.
Date.compare( date1, date2 );
-
date1
First Date object to compare. required -
date2
Second Date object to compare to. required
-
-1
date1 is less than date2. -
0
values are equal. -
1
date1 is greater than date2.
var today = Date.today();
var past = Date.today().add(-6).days();
var future = Date.today().add(6).days();
Date.compare(today, future); // -1
Date.compare(today, new Date().clearTime()); // 0
Date.compare(today, past); // 1
Compares the first Date object to the second Date object and returns true if they are equal.
Date.equals( date1, date2 );
-
date1
Date. First Date object to compare. required -
date2
Date. Second Date object to compare to. required
Boolean. True if dates are equal, False if they are not equal.
var d1 = Date.today();
var d2 = Date.today().addHours(5);
var d3 = new Date().clearTime();
var d4 = "foo";
Date.equals(d1, d2); // false
Date.equals(d1, d3); // true
Date.equals(d1, d4); // throws error
Gets the day number (0-6) if given a culture-specific string which is a valid full or abbreviated day name.
Date.getDayNumberFromName( dayName );
-
dayName
String. The name of the day (eg. "Monday, "Mon", "tuesday", "tue", "We", "we"), etc.
Number. The day number
Date.getDayNumberFromName('Tuesday'); // 2
Date.getDayNumberFromName('sat'); // 6
Date.getDayNumberFromName('SUNDAY'); // 0
Gets the month number (0-11) if given a culture-specific string which is a valid full or abbreviated month name.
Date.getMonthNumberFromName ( monthName );
-
monthName
String. The name of the month (eg. "February, "Feb", "october", "oct").
Number. The month number.
Date.getMonthNumberFromName('January'); // 0
Date.getMonthNumberFromName('feb'); // 1
Date.getMonthNumberFromName('July'); // 6
Date.getMonthNumberFromName('DECEMBER'); // 11
Returns true if the given year is a leap year, false otherwise.
Date.isLeapYear( year )
-
year
Number. The year.
Boolean. True if date is within a LeapYear; otherwise false.
var date1 = new Date(2008,1,29);
var date2 = new Date(2007,1,28);
Date.isLeapYear(date1.getFullYear); // true
Date.isLeapYear(date2.getFullYear); // false
Date.getDaysInMonth ( Number year, Number month ) : NumberGets the number of days in the month, given a year and month value. Automatically corrects for leap year.
- {Number year} The year.* {Number month} The month (0-11).
Date.getDaysInMonth(2008, 1); // 29 Date.getDaysInMonth(2007, 10); // 30 .
Date.getTimezoneAbbreviation ( Number timezoneOffset, Boolean isDayLightSavingsTime ) : String[](#Date.getTimezoneAbbreviation_(_Number_timezoneOffset,_Boolean_is)Returns a culture-specific timezone abbreviation based on a given offset and a boolean indicating whether daylight savings time is in effect.
- {Number timezoneOffset} The year.* {Boolean isDayLightSavingsTime} Whether the date instance is observing Daylight Saving Time (Summer Time)
var today = Date.today(); Date.getTimezoneAbbreviation(today.getTimezoneOffset, today.isDayLightSavingsTime()); // "UTC", "GMT", "EST", "PDT", etc. .
Date.getTimezoneOffset ( String timezoneAbbreviation, Boolean isDayLightSavingsTime ) : Number[](#Date.getTimezoneOffset_(_String_timezoneAbbreviation,_Boolean_is)Gets the timezone offset if given a culture-specific string which is a valid full or abbreviated timezone name and a boolean indicating whether daylight savings time is in effect.#### Parameters
- {Number timezoneAbbreviation} The timezone abbreviation* {Boolean isDayLightSavingsTime} Whether the date instance is observing Daylight Saving Time (Summer Time)
Date.getTimezoneOffset("PST", true); .
Date.parse ( String dateString ) : DateConverts the specified string value into its JavaScript Date equivalent using culture-specific format information.
- {String dateString} The string value to convert into a Date object. required#### Return Value{Date} A Date object or null if the string cannot be converted into a Date.
Date.parse("today") Date.parse("t + 5 d") // today + 5 days Date.parse("next thursday") Date.parse("February 20th 1973?) Date.parse("Thu, 1 July 2004 22:30:00?) .
Date.parseExact ( String dateString, String formatStringOrArray ) : Date[](#Date.parseExact_(_String_dateString,_String_formatStringOrArray)Converts the specified string value into its JavaScript Date equivalent using the specified format (string) or formats (array). The format of the string value must match one of the supplied formats exactly.
- {String dateString} The string value to convert into a Date object. required.* {Object formatStringOrArray} The expected format {String} or an array of expected formats {Array} of the date string. required.
Date.parseExact("10/15/2004", "M/d/yyyy"); // The Date of 15-Oct-2004 Date.parse("15-Oct-2004", "d-MMM-yyyy"); // The Date of 15-Oct-2004 Date.parse("2004.10.15", "yyyy.MM.dd"); // The Date of 15-Oct-2004 Date.parseExact("10/15/2004", ["M/d/yyyy", "MMMM d, yyyy"]); // The Date of 15-Oct-2004 .
Date.validateDay ( Number day, Number fullYear, Number monthNumber ) : Boolean[](#Date.validateDay_(_Number_day,_Number_fullYear,_Number_monthNumb)Validates the number is within an acceptable range for the days in a month [0-MaxDaysInMonth].
- {Number day} The number to check if within range.* {Number fullYear} The number to check if within range.* {Number monthNumber} The number to check if within range.
Date.validateDay(15, 2007, 1); // true, 15-Feb-2007 Date.validateDay(31, 2007, 10); // false, throws RangeError exception .
Date.validateHour ( Number hour ) : BooleanValidates the number is within an acceptable range for hours [0-23]. Returns true if within range, otherwise false.
- {Number hour} The number to check if within range.
Date.validateHour(15); // true Date.validateHour(24); // false, throws RangeError exception .
Date.validateMillisecond ( Number milliseconds ) : BooleanValidates the number is within an acceptable range for milliseconds [0-999]. Returns true if within range, otherwise false.
- {Number milliseconds} The number to check if within range.
Date.validateMillisecond(500); // true .
Date.validateMinute ( Number minutes ) : BooleanValidates the number is within an acceptable range for minutes [0-59]. Returns true if within range, otherwise false.
- {Number minutes} The number to check if within range. #### Return Value{Boolean} true if within range, otherwise false.
Date.validateMinute(45); // true Date.validateMinute(60); // false, throws RangeError exception .
Date.validateMonth ( Number month ) : BooleanValidates the number is within an acceptable range for months [0-11].
- {Number month} The number to check if within range.
Date.validateMonth(0); // true, "January" Date.validateMonth(12); // false, throws RangeError exception .
Date.validateSecond ( Number second ) : BooleanValidates the number is within an acceptable range for seconds [0-59]. Returns true if within range, otherwise false.
- {Number second} The number to check if within range. #### Return Value{Boolean} true if within range, otherwise false.
Date.validateSecond(15); // true Date.validateSecond(60); // false, throws RangeError exception .
Date.validateYear ( Number year ) : BooleanValidates the number is within an acceptable range for years [0-9999].
- {Number year} The number to check if within range.
Date.validateYear(2007); // true