doctype [?][strict] [loose] [none]
Date Formatting And Format Validation
The 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.
These 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.
A 12-element array holding the full month names.
A 12-element array holding month abbreviations
A 7-element array holding full day names
A 7-element array holding day abbreviations
A 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.
These methods are added as part of the Date object itself, and do not need an instantiated Date object.
parseString (stringDate [,stringFormat]) : Date
This 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]) : Boolean
This method is a convenience wrapper around parseString. If parseString returns null, this method returns false. Otherwise, it returns true.
These methods are added to created Date objects. For example:
var d = new Date(); d.methodName();
isBefore (date) : Boolean
Compares the Date object with a passed Date object. If the date is before the passed date object, it returns true. Otherwise, returns false.
isAfter (date) : Boolean
Compares the Date object with a passed Date object. If the date is after the passed date object, it returns true. Otherwise, returns false.
equals (date) : Boolean
Compares the Date object with a passed Date object. If the dates and times are equal, it returns true. Otherwise, returns false.
equalsIgnoreTime (date) : Boolean
Compares 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.
format (stringFormat) : String
Converts the date into a String representation using the format specified. The format string should use the Format Strings above and any other characters.
getDayName () : String
Returns the name of the day of the week for the Date, using the Date.dayNames array.
getDayAbbreviation () : String
Returns the abbreviation of the day of the week for the Date, using the Date.dayAbbreviations array.
getMonthName () : String
Returns the name of the month for the Date, using the Date.monthNames array.
getMonthAbbreviation () : String
Returns the abbrevation of the month for the Date, using the Date.monthAbbreviations array.
clearTime () : Date
Sets the hours, minutes, seconds, and milliseconds values of the date object all to 0 and returns the object.
add (stringInterval, number) : Date
Adds 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.
|All Contents Copyright © Matt Kruse|