Defined In: | Date.js. |
Class: | Date |
Sample date:
'Wed Jan 10 2007 15:05:01 GMT-0600 (Central Standard Time)'
Format Output Description
------ ---------- --------------------------------------------------------------
d 10 Day of the month, 2 digits with leading zeros
D Wed A textual representation of a day, three letters
j 10 Day of the month without leading zeros
l Wednesday A full textual representation of the day of the week
S th English ordinal day of month suffix, 2 chars (use with j)
w 3 Numeric representation of the day of the week
z 9 The julian date, or day of the year (0-365)
W 01 ISO-8601 2-digit week number of year, weeks starting on Monday (00-52)
F January A full textual representation of the month
m 01 Numeric representation of a month, with leading zeros
M Jan Month name abbreviation, three letters
n 1 Numeric representation of a month, without leading zeros
t 31 Number of days in the given month
L 0 Whether it's a leap year (1 if it is a leap year, else 0)
Y 2007 A full numeric representation of a year, 4 digits
y 07 A two digit representation of a year
a pm Lowercase Ante meridiem and Post meridiem
A PM Uppercase Ante meridiem and Post meridiem
g 3 12-hour format of an hour without leading zeros
G 15 24-hour format of an hour without leading zeros
h 03 12-hour format of an hour with leading zeros
H 15 24-hour format of an hour with leading zeros
i 05 Minutes with leading zeros
s 01 Seconds, with leading zeros
O -0600 Difference to Greenwich time (GMT) in hours (Allows +08, without minutes)
P -06:00 Difference to Greenwich time (GMT) with colon between hours and minutes
T CST Timezone setting of the machine running the code
Z -21600 Timezone offset in seconds (negative if west of UTC, positive if east)
var dt = new Date('1/10/2007 03:05:01 PM GMT-0600');
document.write(dt.format('Y-m-d')); //2007-01-10
document.write(dt.format('F j, Y, g:i a')); //January 10, 2007, 3:05 pm
document.write(dt.format('l, \\t\\he dS of F Y h:i:s A')); //Wednesday, the 10th of January 2007 03:05:01 PM
Date.patterns = {
ISO8601Long:"Y-m-d H:i:s",
ISO8601Short:"Y-m-d",
ShortDate: "n/j/Y",
LongDate: "l, F d, Y",
FullDateTime: "l, F d, Y g:i:s A",
MonthDay: "F d",
ShortTime: "g:i A",
LongTime: "g:i:s A",
SortableDateTime: "Y-m-d\\TH:i:s",
UniversalSortableDateTime: "Y-m-d H:i:sO",
YearMonth: "F, Y"
};
var dt = new Date();
document.write(dt.format(Date.patterns.ShortDate));
Property | Description | Defined By | |
---|---|---|---|
Date.DAY :
String
|
Date interval constant
Date interval constant
|
Date | |
Date.HOUR :
String
|
Date interval constant
Date interval constant
|
Date | |
Date.MILLI :
String
|
Date interval constant
Date interval constant
|
Date | |
Date.MINUTE :
String
|
Date interval constant
Date interval constant
|
Date | |
Date.MONTH :
String
|
Date interval constant
Date interval constant
|
Date | |
Date.SECOND :
String
|
Date interval constant
Date interval constant
|
Date | |
Date.YEAR :
String
|
Date interval constant
Date interval constant
|
Date | |
Date.dayNames :
Array
|
An array of textual day names.
An array of textual day names.
Override these values for international dates, for example... Date.dayNames = ['SundayInYourLang', 'MondayInYourLang', ...]; |
Date | |
Date.monthNames :
Array
|
An array of textual month names.
An array of textual month names.
Override these values for international dates, for example... Date.monthNames = ['JanInYourLang', 'FebInYourLang', ...]; |
Date |
Method | Defined By | |
---|---|---|
Parses the passed string using the specified format.
Parses the passed string using the specified format. Note that this function expects dates in normal calendar
format, meaning that months are 1-based (1 = January) and not zero-based like in JavaScript dates. Any part of the date format that is not specified will default to the current date value for that part. Time parts can also be specified, but default to 0. Keep in mind that the input date string must precisely match the specified format string or the parse operation will fail. Example Usage:
|
Date | |
Provides a convenient method of performing basic date arithmetic.
Provides a convenient method of performing basic date arithmetic. This method
does not modify the Date instance being called - it creates and returns a new Date instance containing the resulting date value. Examples:
|
Date | |
Date | ||
clone
()
:
Date
Creates and returns a new Date instance with the exact same date value as the called instance.
Creates and returns a new Date instance with the exact same date value as the called instance.
Dates are copied and passed by reference, so if a copied date variable is modified later, the original variable will also be changed. When the intention is to create a new variable that will not modify the original instance, you should create a clone. Example of correctly cloning a date:
|
Date | |
Date | ||
getDayOfYear
()
:
Number
Get the numeric day number of the year, adjusted for leap year.
Get the numeric day number of the year, adjusted for leap year.
|
Date | |
getDaysInMonth
()
:
Number
Get the number of days in the current month, adjusted for leap year.
Get the number of days in the current month, adjusted for leap year.
|
Date | |
Date | ||
getFirstDateOfMonth
()
:
Date
Get the first date of this date's month
Get the first date of this date's month
|
Date | |
getFirstDayOfMonth
()
:
Number
Get the first day of the current month, adjusted for leap year.
Get the first day of the current month, adjusted for leap year. The returned value
is the numeric day index within the week (0-6) which can be used in conjunction with the {link monthNames} array to retrieve the textual day name. Example:
|
Date | |
getGMTColonOffset
()
:
String
Get the offset from GMT of the current date (equivalent to the format specifier 'P').
Get the offset from GMT of the current date (equivalent to the format specifier 'P').
|
Date | |
getGMTOffset
()
:
String
Get the offset from GMT of the current date (equivalent to the format specifier 'O').
Get the offset from GMT of the current date (equivalent to the format specifier 'O').
|
Date | |
getLastDateOfMonth
()
:
Date
Get the last date of this date's month
Get the last date of this date's month
|
Date | |
getLastDayOfMonth
()
:
Number
Get the last day of the current month, adjusted for leap year.
Get the last day of the current month, adjusted for leap year. The returned value
is the numeric day index within the week (0-6) which can be used in conjunction with the {link monthNames} array to retrieve the textual day name. Example:
|
Date | |
getSuffix
()
:
String
Get the English ordinal suffix of the current day (equivalent to the format specifier 'S').
Get the English ordinal suffix of the current day (equivalent to the format specifier 'S').
|
Date | |
getTimezone
()
:
String
Get the timezone abbreviation of the current date (equivalent to the format specifier 'T').
Get the timezone abbreviation of the current date (equivalent to the format specifier 'T').
|
Date | |
getWeekOfYear
()
:
String
Get the string representation of the numeric week number of the year
(equivalent to the format specifier 'W').
Get the string representation of the numeric week number of the year
(equivalent to the format specifier 'W').
|
Date | |
isLeapYear
()
:
Boolean
Whether or not the current date is in a leap year.
Whether or not the current date is in a leap year.
|
Date |