MailDateFormat (Java EE 5)

Java EE API


javax.mail.internet Class MailDateFormat

java.lang.Object
  extended by java.text.Format
      extended by java.text.DateFormat
          extended by java.text.SimpleDateFormat
              extended by javax.mail.internet.MailDateFormat
All Implemented Interfaces:
Serializable, Cloneable

public class MailDateFormat
extends SimpleDateFormat

Extends: java.text.Format > java.text.DateFormat > java.text.SimpleDateFormat

基于 2000 年 1 月 26 日的 draft-ietf-drums-msg-fmt-08 的格式化和解析日期规范。它是 RFC822 的后续规范。

此类不带模式字符串。它总是基于下面的规范格式化日期。

3.3 日期和时间规范

日期和时间出现在消息的几个头字段中。这部分指定完整的日期和时间规范的语法。尽管整个日期-时间规范允许使用多个空格,但建议在日期-时间规范中需要 FWS 的地方仅使用一个空格,在 FWS 为可选的地方不使用空格;一些原来的实现可能无法正确解释出现的其他多个空格。

date-time = [ day-of-week "," ] date FWS time [CFWS]

day-of-week = ([FWS] day-name) / obs-day-of-week

day-name = "Mon" / "Tue" / "Wed" / "Thu" / "Fri" / "Sat" / "Sun"

date = day month year

year = 4*DIGIT / obs-year

month = (FWS month-name FWS) / obs-month

month-name = "Jan" / "Feb" / "Mar" / "Apr" /
"May" / "Jun" / "Jul" / "Aug" /
"Sep" / "Oct" / "Nov" / "Dec"
 

day = ([FWS] 1*2DIGIT) / obs-day

time = time-of-day FWS zone

time-of-day = hour ":"minute [ ":"second ]

hour = 2DIGIT / obs-hour

minute = 2DIGIT / obs-minute

second = 2DIGIT / obs-second

zone = (( "+" / "-" ) 4DIGIT) / obs-zone

day 是一月中某一天的数字表示。year 是以公元表示的任意年份数值。

time-of-day 指定自指示日期的午夜开始的小时、分钟和秒数(可选)。

date 和 time-of-day 应该表示本地时间。

zone 指定距 date 和 time-of-day 表示的协调世界时(UTC,以前称为“格林威治标准时”)的偏移量。"+" 或 "-" 指示 time-of-day 是提前还是落后于世界时。前两个数字指示与世界时相差的小时数,最后两个数字指示与世界时相差的分钟数。(因此,+hhmm 表示 +(hh * 60 + mm) 分钟,-hhmm 表示 -(hh * 60 + mm) 分钟)。应该使用 "+0000" 形式指示以世界时表示的时区。虽然 "-0000" 也表示世界时,但它用于指示时间是在基于本地时区(而非世界时)的系统中生成的。

日期-时间规范必须在语意上有效。也就是说,day-of-week(如果包含)必须是日期表示的天,数字 day-of-month 必须介于 1 和指定的月(在指定的年中)所允许的天数之间,time-of-day 必须在 00:00:00 到 23:59:60 范围内(秒数允许闰秒,请参见 [STD-12]),zone 必须在 -9959 到 +9959 范围内。

英文文档:

Formats and parses date specification based on the draft-ietf-drums-msg-fmt-08 dated January 26, 2000. This is a followup spec to RFC822.

This class does not take pattern strings. It always formats the date based on the specification below.

3.3 Date and Time Specification

Date and time occur in several header fields of a message. This section specifies the syntax for a full date and time specification. Though folding whitespace is permitted throughout the date-time specification, it is recommended that only a single space be used where FWS is required and no space be used where FWS is optional in the date-time specification; some older implementations may not interpret other occurrences of folding whitespace correctly.

date-time = [ day-of-week "," ] date FWS time [CFWS]

day-of-week = ([FWS] day-name) / obs-day-of-week

day-name = "Mon" / "Tue" / "Wed" / "Thu" / "Fri" / "Sat" / "Sun"

date = day month year

year = 4*DIGIT / obs-year

month = (FWS month-name FWS) / obs-month

month-name = "Jan" / "Feb" / "Mar" / "Apr" /
             "May" / "Jun" / "Jul" / "Aug" /
             "Sep" / "Oct" / "Nov" / "Dec"
 

day = ([FWS] 1*2DIGIT) / obs-day

time = time-of-day FWS zone

time-of-day = hour ":" minute [ ":" second ]

hour = 2DIGIT / obs-hour

minute = 2DIGIT / obs-minute

second = 2DIGIT / obs-second

zone = (( "+" / "-" ) 4DIGIT) / obs-zone

The day is the numeric day of the month. The year is any numeric year in the common era.

The time-of-day specifies the number of hours, minutes, and optionally seconds since midnight of the date indicated.

The date and time-of-day SHOULD express local time.

The zone specifies the offset from Coordinated Universal Time (UTC, formerly referred to as "Greenwich Mean Time") that the date and time-of-day represent. The "+" or "-" indicates whether the time-of-day is ahead of or behind Universal Time. The first two digits indicate the number of hours difference from Universal Time, and the last two digits indicate the number of minutes difference from Universal Time. (Hence, +hhmm means +(hh * 60 + mm) minutes, and -hhmm means -(hh * 60 + mm) minutes). The form "+0000" SHOULD be used to indicate a time zone at Universal Time. Though "-0000" also indicates Universal Time, it is used to indicate that the time was generated on a system that may be in a local time zone other than Universal Time.

A date-time specification MUST be semantically valid. That is, the day-of-the week (if included) MUST be the day implied by the date, the numeric day-of-month MUST be between 1 and the number of days allowed for the specified month (in the specified year), the time-of-day MUST be in the range 00:00:00 through 23:59:60 (the number of seconds allowing for a leap second; see [STD-12]), and the zone MUST be within the range -9959 through +9959.

Since:
JavaMail 1.2
Author:
Max Spivak
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.text.DateFormat
 
Field Summary
 
Fields inherited from class java.text.DateFormat
 
Constructor Summary
 
Method Summary
 StringBuffer
 Date
 void
 void
 
Methods inherited from class java.text.SimpleDateFormat
 
Methods inherited from class java.text.DateFormat
 
Methods inherited from class java.text.Format
 
Methods inherited from class java.lang.Object
 

Constructor Detail

public MailDateFormat()
英文文档:

MailDateFormat

public MailDateFormat()
Method Detail

public StringBuffer format(java.util.Date date, StringBuffer dateStrBuf, java.text.FieldPosition fieldPosition)
将给定的日期按照当前 TimeZone 中 draft-ietf-drums-msg-fmt-08 所指定的格式进行格式化。
date Date 对象
dateStrBuf 格式化字符串
fieldPosition 当前字段的位置
return StringBuffer 格式化 String
since
JavaMail 1.2
英文文档:

format

public StringBuffer format(Date date,
                           StringBuffer dateStrBuf,
                           FieldPosition fieldPosition)
Formats the given date in the format specified by draft-ietf-drums-msg-fmt-08 in the current TimeZone.

Overrides:
format in class SimpleDateFormat
Parameters:
date - the Date object
dateStrBuf - the formatted string
fieldPosition - the current field position
Returns:
StringBuffer the formatted String
Since:
JavaMail 1.2

public java.util.Date parse(String text, java.text.ParsePosition pos)
将给定的日期按照当前 TimeZone 中 draft-ietf-drums-msg-fmt-08 所指定的格式进行解析。
text 要解析的格式化日期
pos 当前解析位置
return 在 Date 对象中解析的日期 (Date)
since
JavaMail 1.2
英文文档:

parse

public Date parse(String text,
                  ParsePosition pos)
Parses the given date in the format specified by draft-ietf-drums-msg-fmt-08 in the current TimeZone.

Overrides:
parse in class SimpleDateFormat
Parameters:
text - the formatted date to be parsed
pos - the current parse position
Returns:
Date the parsed date in a Date object
Since:
JavaMail 1.2

public void setCalendar(java.util.Calendar newCalendar)
不允许设置日历
英文文档:

setCalendar

public void setCalendar(Calendar newCalendar)
Don't allow setting the calendar

Overrides:
setCalendar in class DateFormat

public void setNumberFormat(java.text.NumberFormat newNumberFormat)
不允许设置 NumberFormat
英文文档:

setNumberFormat

public void setNumberFormat(NumberFormat newNumberFormat)
Don't allow setting the NumberFormat

Overrides:
setNumberFormat in class DateFormat


Submit a bug or feature

Copyright 2007 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.

一看就知道只有菜鸟才干这么无知的事啦。

PS : 未经我党受权你也可自由散发此文档。 如有任何错误请自行修正;若因此而造成任何损失请直接找人民主席,请勿与本人联系。谢谢!