key - (string) the key of the value you wish to get
Returns
(mixed) the corresponding value for the key supplied
Notes
All of the native date methods work with get in addition to most of the get... methods added in Date.js. These are: "Date", "Day", "FullYear", "Hours", "Milliseconds", "Minutes", "Month", "Seconds", "Time", "TimezoneOffset", "Week", "Timezone", "GMTOffset", "Ordinal", "DayOfYear", "LastDayOfMonth", "UTCDate", "UTCDay", "UTCFullYear", "AMPM", "UTCHours", "UTCMilliseconds", "UTCMinutes", "UTCMonth", "UTCSeconds"
get is not case sensitive; so you can do get('date')
property - (string) the property that you want to set
value - (mixed) the value for the key
One Argument (properties)
properties - (object) Object with its keys/value pairs representing the properties and values to set for the Date (as described below).
Notes
All of the native date methods work with set. These are: "Date", "FullYear", "Hours", "Milliseconds", "Minutes", "Month", "Seconds", "Time", "UTCDate", "UTCFullYear", "UTCHours", "UTCMilliseconds", "UTCMinutes", "UTCMonth", "UTCSeconds"
set is not case sensitive; so you can do set('date')
format - (string) a string format for the output. Use the keys below with percent signs to get a desired output. Defaults to "%x %X", which renders "12/31/2007 03:45PM"
Keys
a - short day ("Mon", "Tue")
A - full day ("Monday")
b - short month ("Jan", "Feb")
B - full month ("January")
c - the full date to string ("Mon Dec 10 14:35:42 2007"; %a %b %d %H:%m:%S %Y)
d - the date to two digits (01, 05, etc)
e - the date as one digit (1, 5, 12, etc)
H - the hour to two digits in military time (24 hr mode) (00, 11, 14, etc)
I - the hour as a decimal number using a 12-hour clock (range 01 to 12).
j - the day of the year to three digits (001 to 366, is Jan 1st)
k - the hour (24-hour clock) as a digit (range 0 to 23). Single digits are preceded by a blank space.
l - the hour (12-hour clock) as a digit (range 1 to 12). Single digits are preceded by a blank space.
L - the time in milliseconds (three digits; "081")
m - the numerical month to two digits (01 is Jan, 12 is Dec)
M - the minutes to two digits (01, 40, 59)
o - the ordinal of the day of the month in the current language ("st" for the 1st, "nd" for the 2nd, etc.)
p - the current language equivalent of either AM or PM
s - the Unix Epoch Time timestamp
S - the seconds to two digits (01, 40, 59)
T - the time as %H:%M:%S
U - the week to two digits (01 is the week of Jan 1, 52 is the week of Dec 31)
w - the numerical day of the week, one digit (0 is Sunday, 1 is Monday)
x - the date in the current language preferred format. en-US: %m/%d/%Y (12/10/2007)
X - the time in the current language preferred format. en-US: %I:%M%p (02:45PM)
y - the short year (two digits; "07")
Y - the full year (four digits; "2007")
z - the GMT offset ("-0800")
Z - the time zone ("GMT")
% - returns % (example: %y%% = 07%)
Shortcuts
These shortcuts are NOT preceded by the percent sign.
Parses a string to a date. In the examples below, parsing works with dates using / (slash), - (dash), or . (period). (12.31.2007, 12-31-2007, 12/31/2007).
Syntax
Date.parse(date);
new Date().parse(date);
Arguments
date - (string) a string date that has a predefined parser (see Date:defineParser)
Example
Date.parse('10/12/1982')//"Tue Oct 12 1982 00:00:00 GMT-0700 (Pacific Daylight Time)"
Date.parse('10/12/1982 10:45pm')//"Tue Oct 12 1982 22:45:00 GMT-0700 (Pacific Daylight Time)"
Date.parse('10.12.1982 22:45:00')//"Tue Oct 12 1982 22:45:00 GMT-0700 (Pacific Daylight Time)"
Date.parse('2007-06-08 16:34:52')//"Fri Jun 08 2007 16:34:52 GMT-0700 (Pacific Daylight Time)"
Date.parse('2007-06-08T16:34:52+0200')//"Fri Jun 08 2007 07:34:52 GMT-0700 (Pacific Daylight Time)"
Date.parse('Thu Oct 22 08:11:23 +0000 2009')//Thu Oct 12 2009 08:11:23 GMT (Greenwich Mean Time)
Date.parse('1st')//"Sat Dec 01 2007 00:00:00 GMT-0800 (Pacific Standard Time)"
Date.parse('14th October')//"Sun Oct 14 2007 00:00:00 GMT-0700 (Pacific Daylight Time)"
Date.parse('24th May, 2007')//"Thu May 24 2007 00:00:00 GMT-0700 (Pacific Daylight Time)"
Date.parse('May 3rd 2006 10:45pm')//"Wed May 03 2006 22:45:00 GMT-0700 (Pacific Daylight Time)"var PrinceParty = new Date();
PrinceParty.parse('12/31/1999 11:59pm'); //PrinceParty is now set for 12/31/1999 just before midnight
Returns
(date) a Date instance with the parsed value as its date.
Notes
Date.js includes many default parsers, you will get some more if you include Date.Extras.js
If you execute the parse method against an instance of Date, that instance will take on the parsed value
If you execute the parse method against the Date namespace a new Date object is created and returned
If the date was not able to be parsed, you'll still be returned a native Date object that is not a valid date. Use the Date:isValid method to determine if the parse was successful.
name - (string) name of the new format, as lowercase.
format - (string, function) format string (see Date:format)
Example
Date.defineFormat('time', '%H:%M');
new Date().format('time'); //17:30// also possible to pass a function
Date.defineFormat('timeago', function(date){var now = Date.now();
return Math.round((now - date) / (1000 * 60)) + ' minutes ago';
});
Additional parsers can be authored than those already outlined by default in Date.js. If you include Date.Extras.js you'll get several more, but you can write your own.
Syntax
Date.defineParser(pattern);
Arguments
pattern - (string or object) see descriptions below.
Pattern String
A pattern string is somewhat of a hybrid between regular expressions and the format strings passed into Date:format. First, an example:
Date.defineParser('%d%o( %b( %Y)?)?( %X)?');
As you can see, the above pattern (already included in Date.js) uses parentheses for grouping with a question mark to denote the preceding item or group as being optional, just as in a regular expression. It parses strings such as:
14th
31st October
1 Jan 2000
1 Jan 12:00am
All of the same keys that are supported in Date:format are supported here, except %c, %U, %w, and %Z. However, the matching rules for each key is as loose as possible in order to parse the greatest number of variations.
Custom Pattern Object
Each custom pattern object has two properties: a regular expression and a handler that is passed the result of that expression executed on the string to be parsed.