The Date in ExtJs is basically a subset of the PHP date function and represents a Date object. So far. There are few methods provided by the Date class in ExtJs. However, on the other hand, due to historical reasons, there are many letters describing the format variables of Date in any language. This section describes the Date format representation. These are all content in ExtJs API. If you have a Chinese version, you can skip this step. If you want to continue reading, note that the characters in the format are uppercase and lowercase sensitive.
Year
The number of Y years. Four digits, for example, 1999
Double-digit expression of year y, for example, 99 or 03
O iso-october number (the same as Y, but if the number of ISO weeks belongs to the previous year or the next year, that year will be used) for example 1998 or 2004
L whether it is a leap year. 1 indicates a leap year, otherwise 0
Month
The full name of month F. Januray to December
Abbreviated M month text. Jan to Dec
The number of the Month of m, starting from 0. For example, 01 to 12
The number of n months, not starting with 0. 1 to 12
Week
D indicates the abbreviation of the day of the week. For example, Mon to Sun
L like D, it is just the full name, such as Sunday to Saturday
W the number of 7 days in a week indicates 0 (Sunday) to 6 (Saturday)
N ISO-8601 represents a number of seven days a week. 1 indicates Monday to 7 indicates Sunday)
W ISO-8601 the number of weeks in a year. It starts from Monday every week. So 01-53 marked 53 weeks in sequence.
Day
The double digits that start with 0 represent the day of a month. For example, 01 to 31
The content of j is the same as that of d, except that it does not start with 0. For example, 1 to 31
T indicates the number of days in a given month. 28 to 31
The suffix described in S English is used to indicate a period of time in a month. It can be 2 characters in length and can work well with j. For example, st, nd, rd, or th (1st, 2nd, 3rd, 4th)
Z indicates the number of 365 days a year, starting from 0. 0-364, and leap year is 0-365
Last afternoon
Lowercase letters of a AM and PM. For example, am or pm
Uppercase letters of a am and PM. For example, AM or PM
Hour
G does not start with 0 in the 12-hour format, 1 to 12
The format of h starting with 0 in 12 hours, 01 to 12
G is not in the 24-hour format starting with 0, 0 to 23
The 24-hour format starting with 0 for H, ranging from 00 to 23.
Minute
I start with 0 minutes, 00 to 59
Seconds
Seconds starting with 0, 00 to 59
The fractional part of the u second. It must be at least one digit without limitation. For example, 001 indicates 0.001 seconds. 999 indicates 0.999 seconds. 12312312 indicates 0.12312312 seconds.
U starts from the Unix epoch (January 1 1970 00:00:00 GMT) to the current second. For example, 1193432466
The number of seconds in which the current time zone of Z differs from UTC. If it is in the west of UTC, It is a negative number and the East is a positive number. -4300 to 50400
Time Zone
O and Greenwich Mean Time Difference. Example: + 1030
The time difference between the colon and Greenwich Mean Time of P. For example
T stands for the time zone in which the current code machine runs. For example, EST, MDT, and PDT
C iso8601 date representation (Note: if there is a decimal part in the second, it should be at least one digit, not limited. See www.w3.org/tr/note-datetiemto get more content. Example: 2007-04-17t15: 19: 21 + 08: 00 or 2008-03-16t16: 18: 22z or 2009-02-15t17: 17: 23.9 + 01: 00 or 2010-01-14t18: 16: 24, 999876543-07:00
The above is the date format. Pay special attention to the usage process, because sometimes when we customize the format, we may encounter situations where the letters in some words are consistent with the format characters. Of course, at this time, we need to output words instead of the content represented by a date. In this case, escape characters must be used for processing. For example:
VaR dt = new date ('2017/1/10 03:05:01 GMT-0600 ');
Document. write (dt. format ('Y-m-d'); // 2007-01-10
Document. write (dt. format ('f j, Y, g: I A'); // January 10,200 7
Document. write (dt. format ('l, \ t \ he jS \ of f y h: I: s A'); // Wednesday, the 10th of January 2007 03:05:01
The following is a date style object, which is useful in the API. Although it is not part of Date itself. However, flexible application will bring great convenience to program writing.
Date. patterns = {
ISO8601Long: "Y-m-d H: I: s ",
ISO8601Short: "Y-m-d ",
Expiry date: "n/j/Y ",
LongDate: "l, F d, Y ",
FullDateTime: "l, F d, Y g: I: s ",
MonthDay: "F d ",
Processing time: "g: I ",
LongTime: "g: I: s ",
SortableDateTime: "Y-m-d \ TH: I: s ",
UniversalSortableDateTime: "Y-m-d H: I: sO ",
YearMonth: "F, Y"
};
Use Case:
Var dt = new Date ();
Document. write (dt. format (Date. patterns. interval Date ));
Other materials:
Date and Time Format:
Sample Data:
'Wed Jan 10 2007 15:05:01 GMT-0600 (Central Standard Time )'
Format character output description
------------------------------------------------------------------------------
D. The number of days in January, double digits. The number of days is 0"
D Wed: the abbreviation of the current week, three letters
J. The number of days in March. Do not add "0"
L complete spelling of Wednesday in the current week
The suffix of the ordinal number of the day of the month in S th English, two characters (used with the format "j)
W 3 days in a week (1 ~ 7)
Z 9 the number of days in a year (0 ~ 365)
W 01 the number of weeks in a year, two digits (00 ~ 52)
F complete spelling of January's current month
M 01 current month, double-digit, inadequate fill "0"
The complete spelling of M Jan in the current month, with three letters
N 1 The current month. Do not add "0"
T 31 total days of the current month
L whether 0 is a leap year ("1" indicates a leap year, and "0" indicates a year)
Y 2007 the current number of years in four digits
Y 07 the current number of years expressed by two digits
A pm lowercase "am" and "PM"
Uppercase "am" and "PM" for a PM"
The current number of hours in the G 3 12-hour format"
The current hour in g 15 24-hour format. Do not fill in "0"
The current number of hours in the 12-hour format of H03"
The current number of hours in the h 15-24-hour format"
I 05 the number of minutes for filling "0"
S 01: the number of seconds in which the "0" is supplemented by the missing bits
O-0600 differences between hours and GMT
T CST current time zone set by the System
Z-21600 Time Zone offset in seconds (negative in the west and positive in the east)
Example: (Note that you must use the Escape Character "\" before a letter to output it as a letter rather than a format character ):
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
The following are some standard date/time templates that may be useful to you. They are not Date. but you can copy the following code and put it in Date. in any script referenced after js, it becomes a global variable and takes effect on all Date objects. You can add or delete this code segment as needed.
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:
var dt = new Date();
document.write(dt.format(Date.patterns.ShortDate));