Home > Web Front-end > JS Tutorial > Date format character code of ExtJs_extjs

Date format character code of ExtJs_extjs

WBOY
Release: 2016-05-16 18:13:01
Original
866 people have browsed it

The Date class provides few methods in ExtJs. However, on the other hand, due to historical reasons, no matter which language the Date is in, there are many letters characterizing its format variables. This section focuses on the date format representation of Date. These are all contents in the ExtJs API. If there is a Chinese version, you can skip here directly. If you want to continue reading, please note that the format characters are case-sensitive.

Year

Y The numerical representation of the year, 4 digits, such as 1999
y The two-digit representation of the year, such as 99 or 03
o ISO-8601 numerical representation of the year (same as Y, but if the number W of the ISO week belongs to the previous year or the next year, then use that year), such as 1998 or 2004
L Whether it is a leap year. 1 means it is a leap year, otherwise 0

month
F The full name of the month. January to December
M Abbreviation of month text. Jan to Dec
m The numerical representation of the month, starting from 0. For example, 01 to 12
n months are represented by numbers, not starting with 0. 1 to 12

week
D represents the abbreviation of the day of the week. For example, Mon to Sun
l is the same as D, but it is the full name, for example, Sunday to Saturday
w The numbers of 7 days in a week represent 0 (Sunday) to 6 (Saturday)
N ISO-8601 week 7 days numerical representation. 1 represents Monday (Monday) to 7 represents Sunday (Sunday)
W ISO-8601 digital representation of the week in the year. Each week starts on Monday. So there are 01-53, sequentially marking 53 weeks.

Day
d The two digits starting with 0 represent the day of the month. For example, 01 to 31
j has the same content as d, but does not start with 0. For example, 1 to 31
t The number of days in a given month. 28 to 31
S is a suffix described in English, used to indicate the day of the month, 2 characters, and can work well with j. For example, st, nd, rd, or th (1st, 2nd, 3rd, 4th)
z The numerical representation of 365 days in a year, starting from 0. That is, 0-364, and leap years are 0-365

morning and afternoon
a The lower case of AM and PM. For example, am or pm
A AM and PM are capitalized. For example, AM or PM

hour
g 12-hour format not starting with 0, 1 to 12
h 12-hour format starting with 0 Format, 01 to 12
G 24-hour format not starting with 0, 0 to 23
H 24-hour format starting with 0, 00 to 23

Min
i Minutes starting with 0, 00 to 59

Seconds
s Seconds starting with 0, 00 to the fractional part of 59
u seconds. At least one digit, no more. For example, 001 means 0.001 seconds. 999 means 0.999 seconds. 12312312 means 0.12312312 seconds.
U Seconds since the beginning of the Unix epoch (January 1 1970 00:00:00 GMT) to the present. For example, 1193432466
Z is the number of seconds difference between the current time zone and UTC. If it is west of UTC, it is a negative number, and if it is east of UTC, it is a positive number. -4300 to 50400

Time Zone
O The time difference from Greenwich Mean Time. For example, 1030
P with a colon is the time difference from Greenwich Mean Time. For example -08:00
T is the abbreviation of the time zone of the machine running the current code. For example, EST, MDT, PDT
c ISO8601 date representation (note that if the second has a decimal part, it must be at least 1 digit, and there is no limit to more. See www.w3.org/TR/NOTE-datetiem for more information . 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 are the format symbols of Date. Pay special attention when using them, because sometimes when we customize the format, we will encounter letters in some words that are consistent with the format symbols. situation. Of course, what we need to output at this time is the word rather than the content represented by a certain Date, so we must use escape characters at this time.For example:

var dt = new Date('1/10/2007 03:05:01 PM GMT-0600');
document.write(dt.format('Y-m-d')) ; (dt.format('l, \t\he jS \of F Y h:i:s A')); // Wednesday, the 10th of January 2007 03:05:01 PM

The following is given Create a date-style object. This is available in the API and is very easy to use. 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",
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"
};


Use case:


var dt = new Date();
document.write(dt.format(Date.patterns.ShortDate));

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template