NavigationLibrariesdoctype [?][strict] [loose] [none] |
Date Formatting And Format Validation |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The date.js library extends the built-in Date object in javascript by adding class methods and instance methods. No global identifiers are used, so the global namespace stays clean. The goal of the library is to provide additional features for Date objects. The available methods are explained in detail below. Format StringsThe methods to parse and format dates use syntax that is similar to Java's java.text.SimpleDateFormat class with some minor exceptions. In the table below, note the difference between M and m! MM and M are for months, mm and m are for minutes.
Class PropertiesThese properties are added to the Date object for formatting and parsing. For locales other than the default English/American, they should be changed via script. It is not recommended that the values be changed in the js file itself, since that would require the changes to be made to each revision or update of the js file from this site. monthNamesA 12-element array holding the full month names. monthAbbreviationsA 12-element array holding month abbreviations dayNamesA 7-element array holding full day names dayAbbreviationsA 7-element array holding day abbreviations preferAmericanFormatA boolean value used only when parsing date strings when no format is specified. It is used for parsing ambiguous dates like 1/2/2000 - which in 'American' format would mean Jan 2 and in 'European' format would mean Feb 1. The value defaults to 'true' which means to interpret ambiguous dates in American format. Set that value to 'false' to prefer European format. Class MethodsThese methods are added as part of the Date object itself, and do not need an instantiated Date object. parseString (stringDate [,stringFormat]) : DateThis method takes a string representation of a date and converts it to a Date object.
Returns: Date, or null if the string could not be parsed. isValid (stringDate [,stringFormat]) : BooleanThis method is a convenience wrapper around parseString. If parseString returns null, this method returns false. Otherwise, it returns true.
Returns: Boolean Instance MethodsThese methods are added to created Date objects. For example: var d = new Date(); d.methodName(); isBefore (date) : BooleanCompares the Date object with a passed Date object. If the date is before the passed date object, it returns true. Otherwise, returns false.
Returns: Boolean isAfter (date) : BooleanCompares the Date object with a passed Date object. If the date is after the passed date object, it returns true. Otherwise, returns false.
Returns: Boolean equals (date) : BooleanCompares the Date object with a passed Date object. If the dates and times are equal, it returns true. Otherwise, returns false.
Returns: Boolean equalsIgnoreTime (date) : BooleanCompares the Date object with a passed Date object. If the dates values are equal (year, month, date) - regardless of the time values of each- then it returns true. Otherwise, returns false.
Returns: Boolean format (stringFormat) : StringConverts the date into a String representation using the format specified. The format string should use the Format Strings above and any other characters.
Returns: String getDayName () : StringReturns the name of the day of the week for the Date, using the Date.dayNames array. Returns: String getDayAbbreviation () : StringReturns the abbreviation of the day of the week for the Date, using the Date.dayAbbreviations array. Returns: String getMonthName () : StringReturns the name of the month for the Date, using the Date.monthNames array. Returns: String getMonthAbbreviation () : StringReturns the abbrevation of the month for the Date, using the Date.monthAbbreviations array. Returns: String clearTime () : DateSets the hours, minutes, seconds, and milliseconds values of the date object all to 0 and returns the object. Returns: Date add (stringInterval, number) : DateAdds a certain amount of time to a date object. The interval of time to be added and the number of intervals must both be passed.
Returns: Date |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
All Contents Copyright © Matt Kruse |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||