- All Implemented Interfaces:
Serializable,Cloneable
This class does not support methods that influence the format. It always formats the date based on the specification below.
3.3. Date and Time Specification
Date and time occur in several header fields. This section specifies the syntax for a full date and time specification. Though folding white space is permitted throughout the date-time specification, it is RECOMMENDED that a single space be used in each place that FWS appears (whether it is required or optional); some older implementations may not interpret other occurrences of folding white space 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
1900 or later.
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 (i.e., east of) or behind (i.e., west of) 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 and therefore indicates that the date-time contains no information about the local time zone.
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 [STD12]), and the zone MUST be within the range -9959 through +9959.
Synchronization
Date formats are not synchronized. It is recommended to create separate format instances for each thread. If multiple threads access a format concurrently, it must be synchronized externally.
- Since:
- JavaMail 1.2
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classThis class provides the building blocks for date parsing.private classprivate classNested classes/interfaces inherited from class java.text.DateFormat
DateFormat.Field -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intprivate static final Loggerprivate static final Stringprivate static final longprivate static final intprivate static final TimeZoneFields inherited from class java.text.DateFormat
AM_PM_FIELD, calendar, DATE_FIELD, DAY_OF_WEEK_FIELD, DAY_OF_WEEK_IN_MONTH_FIELD, DAY_OF_YEAR_FIELD, DEFAULT, ERA_FIELD, FULL, HOUR_OF_DAY0_FIELD, HOUR_OF_DAY1_FIELD, HOUR0_FIELD, HOUR1_FIELD, LONG, MEDIUM, MILLISECOND_FIELD, MINUTE_FIELD, MONTH_FIELD, numberFormat, SECOND_FIELD, SHORT, TIMEZONE_FIELD, WEEK_OF_MONTH_FIELD, WEEK_OF_YEAR_FIELD, YEAR_FIELD -
Constructor Summary
ConstructorsConstructorDescriptionCreate a new date format for the RFC2822 specification with lenient parsing. -
Method Summary
Modifier and TypeMethodDescriptionvoidapplyLocalizedPattern(String pattern) This method always throws an UnsupportedOperationException and should not be used because RFC 2822 mandates a specific pattern.voidapplyPattern(String pattern) This method always throws an UnsupportedOperationException and should not be used because RFC 2822 mandates a specific pattern.clone()Overrides Cloneable.format(Date date, StringBuffer dateStrBuf, FieldPosition fieldPosition) Formats the given date in the format specified by RFC 2822 in the current TimeZone.This method always throws an UnsupportedOperationException and should not be used because RFC 2822 mandates another strategy for interpreting 2-digits years.parse(String text, ParsePosition pos) Parses the given date in the format specified by RFC 2822.private voidAllows to deserialize instances that were serialized with the previous implementation.voidset2DigitYearStart(Date startDate) This method always throws an UnsupportedOperationException and should not be used because RFC 2822 mandates another strategy for interpreting 2-digits years.voidsetCalendar(Calendar newCalendar) This method always throws an UnsupportedOperationException and should not be used because RFC 2822 mandates a specific calendar.voidsetDateFormatSymbols(DateFormatSymbols newFormatSymbols) This method always throws an UnsupportedOperationException and should not be used because RFC 2822 mandates specific date format symbols.voidsetNumberFormat(NumberFormat newNumberFormat) This method always throws an UnsupportedOperationException and should not be used because RFC 2822 mandates a specific number format.private voidsuperApplyPattern(String pattern) This method allows serialization to change the pattern.private DatetoDate(int dayName, int day, int month, int year, int hour, int minute, int second, int zone) Returns the date, as specified by the parameters.private ObjectAllows to serialize instances such that they are deserializable with the previous implementation.Methods inherited from class java.text.SimpleDateFormat
equals, formatToCharacterIterator, getDateFormatSymbols, hashCode, toLocalizedPattern, toPatternMethods inherited from class java.text.DateFormat
format, format, getAvailableLocales, getCalendar, getDateInstance, getDateInstance, getDateInstance, getDateTimeInstance, getDateTimeInstance, getDateTimeInstance, getInstance, getNumberFormat, getTimeInstance, getTimeInstance, getTimeInstance, getTimeZone, isLenient, parse, parseObject, setLenient, setTimeZoneMethods inherited from class java.text.Format
format, parseObject
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
PATTERN
- See Also:
-
LOGGER
-
UNKNOWN_DAY_NAME
private static final int UNKNOWN_DAY_NAME- See Also:
-
UTC
-
LEAP_SECOND
private static final int LEAP_SECOND- See Also:
-
-
Constructor Details
-
MailDateFormat
public MailDateFormat()Create a new date format for the RFC2822 specification with lenient parsing.
-
-
Method Details
-
writeReplace
Allows to serialize instances such that they are deserializable with the previous implementation.- Returns:
- the object to be serialized
- Throws:
ObjectStreamException- never
-
readObject
Allows to deserialize instances that were serialized with the previous implementation.- Parameters:
in- the stream containing the serialized object- Throws:
IOException- on read failuresClassNotFoundException- never
-
clone
Overrides Cloneable.- Overrides:
clonein classSimpleDateFormat- Returns:
- a clone of this instance
- Since:
- JavaMail 1.6
-
format
Formats the given date in the format specified by RFC 2822 in the current TimeZone.- Overrides:
formatin classSimpleDateFormat- Parameters:
date- the Date objectdateStrBuf- the formatted stringfieldPosition- the current field position- Returns:
- StringBuffer the formatted String
- Since:
- JavaMail 1.2
-
parse
Parses the given date in the format specified by RFC 2822.- With strict parsing, obs-* tokens are unsupported. Lenient parsing supports obs-year and obs-zone, with the exception of the 1-character military time zones.
- The optional CFWS token at the end is not parsed.
- RFC 2822 specifies that a zone of "-0000" indicates that the date-time contains no information about the local time zone. This class uses the UTC time zone in this case.
- Overrides:
parsein classSimpleDateFormat- Parameters:
text- the formatted date to be parsedpos- the current parse position- Returns:
- Date the parsed date. In case of error, returns null.
- Since:
- JavaMail 1.2
-
setCalendar
This method always throws an UnsupportedOperationException and should not be used because RFC 2822 mandates a specific calendar.- Overrides:
setCalendarin classDateFormat- Throws:
UnsupportedOperationException- if this method is invoked
-
setNumberFormat
This method always throws an UnsupportedOperationException and should not be used because RFC 2822 mandates a specific number format.- Overrides:
setNumberFormatin classDateFormat- Throws:
UnsupportedOperationException- if this method is invoked
-
applyLocalizedPattern
This method always throws an UnsupportedOperationException and should not be used because RFC 2822 mandates a specific pattern.- Overrides:
applyLocalizedPatternin classSimpleDateFormat- Throws:
UnsupportedOperationException- if this method is invoked- Since:
- JavaMail 1.6
-
applyPattern
This method always throws an UnsupportedOperationException and should not be used because RFC 2822 mandates a specific pattern.- Overrides:
applyPatternin classSimpleDateFormat- Throws:
UnsupportedOperationException- if this method is invoked- Since:
- JavaMail 1.6
-
superApplyPattern
This method allows serialization to change the pattern. -
get2DigitYearStart
This method always throws an UnsupportedOperationException and should not be used because RFC 2822 mandates another strategy for interpreting 2-digits years.- Overrides:
get2DigitYearStartin classSimpleDateFormat- Returns:
- the start of the 100-year period into which two digit years are parsed
- Throws:
UnsupportedOperationException- if this method is invoked- Since:
- JavaMail 1.6
-
set2DigitYearStart
This method always throws an UnsupportedOperationException and should not be used because RFC 2822 mandates another strategy for interpreting 2-digits years.- Overrides:
set2DigitYearStartin classSimpleDateFormat- Throws:
UnsupportedOperationException- if this method is invoked- Since:
- JavaMail 1.6
-
setDateFormatSymbols
This method always throws an UnsupportedOperationException and should not be used because RFC 2822 mandates specific date format symbols.- Overrides:
setDateFormatSymbolsin classSimpleDateFormat- Throws:
UnsupportedOperationException- if this method is invoked- Since:
- JavaMail 1.6
-
toDate
private Date toDate(int dayName, int day, int month, int year, int hour, int minute, int second, int zone) Returns the date, as specified by the parameters.- Returns:
- the date, as specified by the parameters
- Throws:
IllegalArgumentException- if this instance's Calendar is non-lenient and any of the parameters have invalid values, or if dayName is not consistent with day-month-year
-