Built-In Class Date

Defined In: Date.js.
Class:Date
The date parsing and format syntax is a subset of
PHP's date() function, and the formats that are
supported will provide results equivalent to their PHP versions.

Following is the list of all currently supported formats:

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)


Example usage (note that you must escape format specifiers with '\\' to render them as character literals):

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


Here are some standard date/time patterns that you might find helpful. They
are not part of the source of Date.js, but to use them you can simply copy this
block of code into any script that is included after Date.js and they will also become
globally available on the Date object. Feel free to add or remove patterns as needed in your code.

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"
};


Example usage:

var dt = new Date();
document.write(dt.format(Date.patterns.ShortDate));
Class Comments / Notes => [Add Your comment/notes about this class]
Config Options - Has None
Public Properties
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
Public Methods
Method Defined By
Events - Has None
Documentation generated by Introspection Doc Generator on Fri Jul 13 2018 14:10:53 GMT+0800 (HKT) Based on JsDoc Toolkit