public class MailDateFormat
extends java.text.SimpleDateFormat
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. 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-zoneThe 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.
Modifier and Type | Field and Description |
---|---|
private static java.util.Calendar |
cal |
(package private) static boolean |
debug
method of what to look for:
skip WS
skip day "," (this is "Mon", "Tue")
skip WS
parse number (until WS) ==> 1*2DIGIT (day of month)
skip WS
parse alpha chars (until WS) ==> find month
skip WS
parse number (until WS) ==> 2*4DIGIT (year)
skip WS
// now looking for time
parse number (until ':') ==> hours
parse number (until ':') ==> minutes
parse number (until WS) ==> seconds
// now look for Time Zone
skip WS
if ('+' or '-') then numerical time zone offset
if (alpha) then alpha time zone offset
|
private static MailLogger |
logger |
private static long |
serialVersionUID |
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 and Description |
---|
MailDateFormat() |
Modifier and Type | Method and Description |
---|---|
java.lang.StringBuffer |
format(java.util.Date date,
java.lang.StringBuffer dateStrBuf,
java.text.FieldPosition fieldPosition)
Formats the given date in the format specified by
RFC 2822 in the current TimeZone.
|
private static java.util.Date |
ourUTC(int year,
int mon,
int mday,
int hour,
int min,
int sec,
int tzoffset,
boolean lenient) |
java.util.Date |
parse(java.lang.String text,
java.text.ParsePosition pos)
Parses the given date in the format specified by
RFC 2822 in the current TimeZone.
|
private static java.util.Date |
parseDate(char[] orig,
java.text.ParsePosition pos,
boolean lenient)
create a Date by parsing the char array
|
void |
setCalendar(java.util.Calendar newCalendar)
Don't allow setting the calendar
|
void |
setNumberFormat(java.text.NumberFormat newNumberFormat)
Don't allow setting the NumberFormat
|
applyLocalizedPattern, applyPattern, clone, equals, formatToCharacterIterator, get2DigitYearStart, getDateFormatSymbols, hashCode, set2DigitYearStart, setDateFormatSymbols, toLocalizedPattern, toPattern
format, format, getAvailableLocales, getCalendar, getDateInstance, getDateInstance, getDateInstance, getDateTimeInstance, getDateTimeInstance, getDateTimeInstance, getInstance, getNumberFormat, getTimeInstance, getTimeInstance, getTimeInstance, getTimeZone, isLenient, parse, parseObject, setLenient, setTimeZone
private static final long serialVersionUID
static boolean debug
private static MailLogger logger
private static final java.util.Calendar cal
public java.lang.StringBuffer format(java.util.Date date, java.lang.StringBuffer dateStrBuf, java.text.FieldPosition fieldPosition)
format
in class java.text.SimpleDateFormat
date
- the Date objectdateStrBuf
- the formatted stringfieldPosition
- the current field positionpublic java.util.Date parse(java.lang.String text, java.text.ParsePosition pos)
parse
in class java.text.SimpleDateFormat
text
- the formatted date to be parsedpos
- the current parse positionprivate static java.util.Date parseDate(char[] orig, java.text.ParsePosition pos, boolean lenient)
private static java.util.Date ourUTC(int year, int mon, int mday, int hour, int min, int sec, int tzoffset, boolean lenient)
public void setCalendar(java.util.Calendar newCalendar)
setCalendar
in class java.text.DateFormat
public void setNumberFormat(java.text.NumberFormat newNumberFormat)
setNumberFormat
in class java.text.DateFormat