且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

【转】ExtJS DateField 日期控件Format格式化

更新时间:2022-09-16 19:20:54

日期格式参考extjs api文档中的Date类型.
var md = new Ext.form.DateField({
............
format: 'Y-m-d H:i:s',
............
});
替换'Y-m-d H:i:s'中的各个字母,当然增加和减少都没有问题,留意大小写.可得到多种样式的日期格式.
Ext.Date的格式说明
d 01 to 31
D Mon to Sun
j 1 to 31
l Sunday to Saturday
N 1 (for Monday) through 7 (for Sunday)
S st, nd, rd or th. Works well with j
w 0 (for Sunday) to 6 (for Saturday)
z 0 to 364 (365 in leap years)
W 01 to 53
F January to December
m 01 to 12
M Jan to Dec
n 1 to 12
t 28 to 31
L 1 if it is a leap year, 0 otherwise.
o Examples: 1998 or 2004
Y Examples: 1999 or 2003
y Examples: 99 or 03
a am or pm
A AM or PM
g 1 to 12
G 0 to 23
h 01 to 12
H 00 to 23
i 00 to 59
s 00 to 59
u 001 to 999
O Example: +1030
P Example: -08:00
T Examples: EST, MDT, PDT ...
Z -43200 to 50400
c 2007-04-17T15:19:21+08:00
U 1193432466 or -2138434463
补充:20090416
下面列出的是目前所有支持的格式:样本数据:
'Wed Jan 10 2007 15:05:01 GMT-0600 (中区标准时间)'
格式符 输出 说明
------ ---------- --------------------------------------------------------------
d 10 月份中的天数,两位数字,不足位补“0”
D Wed 当前星期的缩写,三个字母
j 10 月份中的天数,不补“0”
l Wednesday 当前星期的完整拼写
S th 英语中月份天数的序数词的后缀,2个字符(与格式符“j”连用)
w 3 一周之中的天数(1~7)
z 9 一年之中的天数(0~365)
W 01 一年之中的周数,两位数字(00~52)
F January 当前月份的完整拼写
m 01 当前的月份,两位数字,不足位补“0”
M Jan 当前月份的完整拼写,三个字母
n 1 当前的月份,不补“0”
t 31 当前月份的总天数
L 0 是否闰年(“1”为闰年,“0”为平年)
Y 2007 4位数字表示的当前年数
y 07 2位数字表示的当前年数
a pm 小写的“am”和“pm”
A PM 大写的“am”和“pm”
g 3 12小时制表示的当前小时数,不补“0”
G 15 24小时制表示的当前小时数,不补“0”
h 03 12小时制表示的当前小时数,不足位补“0”
H 15 24小时制表示的当前小时数,不足位补“0”
i 05 不足位补“0”的分钟数
s 01 不足位补“0”的秒数
O -0600 用小时数表示的与 GMT 差异数
T CST 当前系统设定的时区
Z -21600 用秒数表示的时区偏移量(西方为负数,东方为正数)用法举例:(注意你必须在字母前使用转意字符“\\”才能将其作为字母本身而不是格式符输出):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.js 的一部分,但是你可以将下列代码拷出,并放在 Date.js 之后所引用的任何脚本内,都将成为一个全局变量,并对所有的 Date 对象起作用。你可以按照你的需要随意增加、删除此段代码。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));



本文转自齐师傅博客园博客,原文链接:http://www.cnblogs.com/youring2/archive/2013/02/21/2920943.html,如需转载请自行联系原作者