Ext 2.1 框架浏览(二):时间日期处理

作者:Hily 原始链接:http://hily.me/blog/2008/07/ext21-datetime/
版权声明:可以转载,转载时务必以超链接形式标明文章原始出处作者信息版权声明

第二部分:时间日期处理

定义于 Date.js。

Date 类

------

属性:

把这些属性用 document.write 输出,前面几个用大写的是单位,后面的是星期和月份的名称,最后一个比较奇怪。

要汉化时改一下这几个属性的值应该就可以了。

String Date.DAY

d

String Date.HOUR

h

String Date.MILLI

ms

String Date.MINUTE

mi

String Date.MONTH

mo

String Date.SECOND

s

String Date.YEAR

y

Array Date.dayNames

Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday

Object Date.formatCodes

[object Object]

可以自定义日期格式,如:Date.formatCodes.x = "String.leftPad(this.getDate(), 2, '0')";

Array Date.monthNames

January,February,March,April,May,June,July,August,September,October,November,December

Object Date.monthNumbers

[object Object]

这是一个 Hash 数组,键为月份名缩写(如 Jul),值为月份序号,从 0 开始。

方法:

Number Date.getMonthNumber(String name)

根据缩写的或完整的月份名称,取得从 0 开始的月份序号。

String Date.getShortDayNum(Number day)

根据输入的星期几序号(由 0 开始),取得星期几的缩写(第一天是 Sunday)。

String Date.getShortMonthName(Number month)

根据输入的月份序号(由 0 开始),取得月份的缩写。

Date Date.parseDate(String input, String format)

根据指定格式 format 分析传入的时间字符串,返回一个 Date 对象。

Date add(String interval, Number value)

按指定时间单位 interval 增加或减少时间编移。

Boolean between(Date start, Date end)

判断当前时间是否在两个时间之间。

Date clearTime(Boolean clone)

清空当前时间对象中的所有时间信息。

clone 默认为 false,为 true 时返回当前时间对象的克隆。

Date clone()

返回一个时间对象的精确克隆。

String format(String format)

根据指定格式,格式化返回时间字符串。

Number getDayOfYear()

取得当前时间对象在一年中天的序号,0-364(闰年0-365)。

Number getDaysInMonth()

取得当月的天数。

Number getElapse([Date date])

返回当前时间对象距指定时间的微秒数,date 为空,则默认为 now。

Date getFirstDateOfMonth()

返回当前时间对象所在月份第一天的时间对象。

Number getFirstDayOfMonth()

取得当前时间对象所在月份的第一天是星期几(0-6)。

String getGMTOffset(Boolean colon)

返回时区偏移字符串,格式如:'+0800'。

colon 默认为 false,取 true 时会在小时和分钟之间加上冒号。

Date getLastDateOfMonth()

返回当前时间对象所在月份中最后一天的时间对象。

Number getLastDayOfMonth()

取得当前时间对象所在月份的最后一天是星期几(0-6)。

String getSuffix()

取得当前时间对象中天的英文序数后缀,返回值为 'st', 'nd', 'rd' 或 'th'。

String getTimezone()

取得时区名,如 'CST', 'PDT', 'EDT' 等。

Number getWeekOfYear()

返回当前时间对象处于一年中的第几周(1-53)。

Boolean isLeapYear()

判断当前时间对象是否处在闰年。

 

-- EOF --

发表一下您的高见

If you have any question, or for the language problem, please fell free to leave a comment or just contact me with email: hilyjiang [At] Gmail.