日期中带的 T 是什么意思
Date and Time Formats
Submitted to W3C 15 September 1997
- This version:
- http://www.w3.org/TR/1998/NOTE-datetime-19980827
- Newest version:
- http://www.w3.org/TR/NOTE-datetime
- Authors:
- Misha Wolf <misha.wolf@reuters.com>
Charles Wicksteed <charles.wicksteed@reuters.com> - Document Status
Status of this document
This document is a NOTE made available by the W3 Consortium for discussion only. This indicates no endorsement of its content, nor that the Consortium has, is, or will be allocating any resources to the issues addressed by the NOTE.
This document is a submission to W3C from Reuters Limited. Please see Acknowledged Submissions to W3C regarding its disposition.
Comments on this document should be sent to datetime-comments@w3.org.
Abstract
This document defines a profile of ISO 8601, the International Standard for the representation of dates and times. ISO 8601 describes a large number of date/time formats. To reduce the scope for error and the complexity of software, it is useful to restrict the supported formats to a small number. This profile defines a few date/time formats, likely to satisfy most requirements.
Introduction
The International Standard for the representation of dates and times is ISO 8601. Its full reference number is ISO 8601 : 1988 (E), and its title is "Data elements and interchange formats - Information interchange - Representation of dates and times". A discussion of ISO 8601 has been written by Markus Kuhn.
ISO 8601 describes a large number of date/time formats. For example it defines Basic Format, without punctuation, and Extended Format, with punctuation, and it allows elements to be omitted. This profile defines a restricted range of formats, all of which are valid ISO 8601 dates and times. The aim is to simplify the use of ISO 8601 in World Wide Web-related standards, and to avoid the need for the developers and users of these standards to obtain copies of ISO 8601 itself.
A particular problem with ISO 8601 is that it allows the century to be omitted from years, which is likely to cause trouble as we approach the year 2000. This profile avoids the problem by expressing the year as four digits in all cases.
This profile may be adopted by standards which require an unambiguous representation of dates and times. As different standards have their own requirements regarding granularity and flexibility, this profile offers a number of options. An adopting standard must specify which of these options it permits.
Formats
Different standards may need different levels of granularity in the date and time, so this profile defines six levels. Standards that reference this profile should specify one or more of these granularities. If a given standard allows more than one granularity, it should specify the meaning of the dates and times with reduced precision, for example, the result of comparing two dates with different precisions.
The formats are as follows. Exactly the components shown here must be present, with exactly this punctuation. Note that the "T" appears literally in the string, to indicate the beginning of the time element, as specified in ISO 8601.
Year: YYYY (eg 1997) Year and month: YYYY-MM (eg 1997-07) Complete date: YYYY-MM-DD (eg 1997-07-16) Complete date plus hours and minutes: YYYY-MM-DDThh:mmTZD (eg 1997-07-16T19:20+01:00) Complete date plus hours, minutes and seconds: YYYY-MM-DDThh:mm:ssTZD (eg 1997-07-16T19:20:30+01:00) Complete date plus hours, minutes, seconds and a decimal fraction of a second YYYY-MM-DDThh:mm:ss.sTZD (eg 1997-07-16T19:20:30.45+01:00)
where:
YYYY = four-digit year MM = two-digit month (01=January, etc.) DD = two-digit day of month (01 through 31) hh = two digits of hour (00 through 23) (am/pm NOT allowed) mm = two digits of minute (00 through 59) ss = two digits of second (00 through 59) s = one or more digits representing a decimal fraction of a second TZD = time zone designator (Z or +hh:mm or -hh:mm)
This profile does not specify how many digits may be used to represent the decimal fraction of a second. An adopting standard that permits fractions of a second must specify both the minimum number of digits (a number greater than or equal to one) and the maximum number of digits (the maximum may be stated to be "unlimited").
This profile defines two ways of handling time zone offsets:
- Times are expressed in UTC (Coordinated Universal Time), with a special UTC designator ("Z").
- Times are expressed in local time, together with a time zone offset in hours and minutes. A time zone offset of "+hh:mm" indicates that the date/time uses a local time zone which is "hh" hours and "mm" minutes ahead of UTC. A time zone offset of "-hh:mm" indicates that the date/time uses a local time zone which is "hh" hours and "mm" minutes behind UTC.
A standard referencing this profile should permit one or both of these ways of handling time zone offsets.
Examples
1994-11-05T08:15:30-05:00 corresponds to November 5, 1994, 8:15:30 am, US Eastern Standard Time.
1994-11-05T13:15:30Z corresponds to the same instant.
Acknowledgments
This document draws on Chris Newman's Internet Draft "Date and Time on the Internet" (draft-newman-datetime-01.txt).
https://www.w3.org/TR/NOTE-datetime
/** * Utilities methods for manipulating dates in iso8601 format. This is much much faster and GC friendly than using SimpleDateFormat so * highly suitable if you (un)serialize lots of date objects. * * Supported parse format: [yyyy-MM-dd|yyyyMMdd][T(hh:mm[:ss[.sss]]|hhmm[ss[.sss]])]?[Z|[+-]hh[:]mm]] * * @see <a href="http://www.w3.org/TR/NOTE-datetime">this specification</a> */ @Deprecated // since 2.9 public class ISO8601Utils { protected final static int DEF_8601_LEN = "yyyy-MM-ddThh:mm:ss.SSS+00:00".length(); /** * Timezone we use for 'Z' in ISO-8601 date/time values: since 2.7 * {@link #TIMEZONE_UTC}; with earlier versions up to 2.7 was {@link #TIMEZONE_GMT}. */ private static final TimeZone TIMEZONE_Z = TimeZone.getTimeZone("UTC"); /* /********************************************************** /* Formatting /********************************************************** */ /** * Format a date into 'yyyy-MM-ddThh:mm:ssZ' (default timezone, no milliseconds precision) * * @param date the date to format * @return the date formatted as 'yyyy-MM-ddThh:mm:ssZ' */ public static String format(Date date) { return format(date, false, TIMEZONE_Z); } /** * Format a date into 'yyyy-MM-ddThh:mm:ss[.sss]Z' (GMT timezone) * * @param date the date to format * @param millis true to include millis precision otherwise false * @return the date formatted as 'yyyy-MM-ddThh:mm:ss[.sss]Z' */ public static String format(Date date, boolean millis) { return format(date, millis, TIMEZONE_Z); } @Deprecated // since 2.9 public static String format(Date date, boolean millis, TimeZone tz) { return format(date, millis, tz, Locale.US); } /** * Format date into yyyy-MM-ddThh:mm:ss[.sss][Z|[+-]hh:mm] * * @param date the date to format * @param millis true to include millis precision otherwise false * @param tz timezone to use for the formatting (UTC will produce 'Z') * @return the date formatted as yyyy-MM-ddThh:mm:ss[.sss][Z|[+-]hh:mm] * * @since 2.9 */ public static String format(Date date, boolean millis, TimeZone tz, Locale loc) { Calendar calendar = new GregorianCalendar(tz, loc); calendar.setTime(date); // estimate capacity of buffer as close as we can (yeah, that's pedantic ;) StringBuilder sb = new StringBuilder(30); sb.append(String.format( "%04d-%02d-%02dT%02d:%02d:%02d", calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1, calendar.get(Calendar.DAY_OF_MONTH), calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), calendar.get(Calendar.SECOND) )); if (millis) { sb.append(String.format(".%03d", calendar.get(Calendar.MILLISECOND))); } int offset = tz.getOffset(calendar.getTimeInMillis()); if (offset != 0) { int hours = Math.abs((offset / (60 * 1000)) / 60); int minutes = Math.abs((offset / (60 * 1000)) % 60); sb.append(String.format("%c%02d:%02d", (offset < 0 ? '-' : '+'), hours, minutes)); } else { sb.append('Z'); } return sb.toString(); } /* /********************************************************** /* Parsing /********************************************************** */ /** * Parse a date from ISO-8601 formatted string. It expects a format * [yyyy-MM-dd|yyyyMMdd][T(hh:mm[:ss[.sss]]|hhmm[ss[.sss]])]?[Z|[+-]hh:mm]] * * @param date ISO string to parse in the appropriate format. * @param pos The position to start parsing from, updated to where parsing stopped. * @return the parsed date * @throws ParseException if the date is not in the appropriate format */ public static Date parse(String date, ParsePosition pos) throws ParseException { Exception fail = null; try { int offset = pos.getIndex(); // extract year int year = parseInt(date, offset, offset += 4); if (checkOffset(date, offset, '-')) { offset += 1; } // extract month int month = parseInt(date, offset, offset += 2); if (checkOffset(date, offset, '-')) { offset += 1; } // extract day int day = parseInt(date, offset, offset += 2); // default time value int hour = 0; int minutes = 0; int seconds = 0; int milliseconds = 0; // always use 0 otherwise returned date will include millis of current time // if the value has no time component (and no time zone), we are done boolean hasT = checkOffset(date, offset, 'T'); if (!hasT && (date.length() <= offset)) { Calendar calendar = new GregorianCalendar(year, month - 1, day); pos.setIndex(offset); return calendar.getTime(); } if (hasT) { // extract hours, minutes, seconds and milliseconds hour = parseInt(date, offset += 1, offset += 2); if (checkOffset(date, offset, ':')) { offset += 1; } minutes = parseInt(date, offset, offset += 2); if (checkOffset(date, offset, ':')) { offset += 1; } // second and milliseconds can be optional if (date.length() > offset) { char c = date.charAt(offset); if (c != 'Z' && c != '+' && c != '-') { seconds = parseInt(date, offset, offset += 2); if (seconds > 59 && seconds < 63) seconds = 59; // truncate up to 3 leap seconds // milliseconds can be optional in the format if (checkOffset(date, offset, '.')) { offset += 1; int endOffset = indexOfNonDigit(date, offset + 1); // assume at least one digit int parseEndOffset = Math.min(endOffset, offset + 3); // parse up to 3 digits int fraction = parseInt(date, offset, parseEndOffset); // compensate for "missing" digits switch (parseEndOffset - offset) { // number of digits parsed case 2: milliseconds = fraction * 10; break; case 1: milliseconds = fraction * 100; break; default: milliseconds = fraction; } offset = endOffset; } } } } // extract timezone if (date.length() <= offset) { throw new IllegalArgumentException("No time zone indicator"); } TimeZone timezone = null; char timezoneIndicator = date.charAt(offset); if (timezoneIndicator == 'Z') { timezone = TIMEZONE_Z; offset += 1; } else if (timezoneIndicator == '+' || timezoneIndicator == '-') { String timezoneOffset = date.substring(offset); offset += timezoneOffset.length(); // 18-Jun-2015, tatu: Minor simplification, skip offset of "+0000"/"+00:00" if ("+0000".equals(timezoneOffset) || "+00:00".equals(timezoneOffset)) { timezone = TIMEZONE_Z; } else { // 18-Jun-2015, tatu: Looks like offsets only work from GMT, not UTC... // not sure why, but that's the way it looks. Further, Javadocs for // `java.util.TimeZone` specifically instruct use of GMT as base for // custom timezones... odd. String timezoneId = "GMT" + timezoneOffset; // String timezoneId = "UTC" + timezoneOffset; timezone = TimeZone.getTimeZone(timezoneId); String act = timezone.getID(); if (!act.equals(timezoneId)) { /* 22-Jan-2015, tatu: Looks like canonical version has colons, but we may be given * one without. If so, don't sweat. * Yes, very inefficient. Hopefully not hit often. * If it becomes a perf problem, add 'loose' comparison instead. */ String cleaned = act.replace(":", ""); if (!cleaned.equals(timezoneId)) { throw new IndexOutOfBoundsException("Mismatching time zone indicator: "+timezoneId+" given, resolves to " +timezone.getID()); } } } } else { throw new IndexOutOfBoundsException("Invalid time zone indicator '" + timezoneIndicator+"'"); } Calendar calendar = new GregorianCalendar(timezone); calendar.setLenient(false); calendar.set(Calendar.YEAR, year); calendar.set(Calendar.MONTH, month - 1); calendar.set(Calendar.DAY_OF_MONTH, day); calendar.set(Calendar.HOUR_OF_DAY, hour); calendar.set(Calendar.MINUTE, minutes); calendar.set(Calendar.SECOND, seconds); calendar.set(Calendar.MILLISECOND, milliseconds); pos.setIndex(offset); return calendar.getTime(); // If we get a ParseException it'll already have the right message/offset. // Other exception types can convert here. } catch (Exception e) { fail = e; } String input = (date == null) ? null : ('"' + date + '"'); String msg = fail.getMessage(); if (msg == null || msg.isEmpty()) { msg = "("+fail.getClass().getName()+")"; } ParseException ex = new ParseException("Failed to parse date " + input + ": " + msg, pos.getIndex()); ex.initCause(fail); throw ex; }
com.fasterxml.jackson.databind.util.ISO8601Utils
/** * <code>SimpleDateFormat</code> is a concrete class for formatting and * parsing dates in a locale-sensitive manner. It allows for formatting * (date → text), parsing (text → date), and normalization. * * <p> * <code>SimpleDateFormat</code> allows you to start by choosing * any user-defined patterns for date-time formatting. However, you * are encouraged to create a date-time formatter with either * <code>getTimeInstance</code>, <code>getDateInstance</code>, or * <code>getDateTimeInstance</code> in <code>DateFormat</code>. Each * of these class methods can return a date/time formatter initialized * with a default format pattern. You may modify the format pattern * using the <code>applyPattern</code> methods as desired. * For more information on using these methods, see * {@link DateFormat}. * * <h3>Date and Time Patterns</h3> * <p> * Date and time formats are specified by <em>date and time pattern</em> * strings. * Within date and time pattern strings, unquoted letters from * <code>'A'</code> to <code>'Z'</code> and from <code>'a'</code> to * <code>'z'</code> are interpreted as pattern letters representing the * components of a date or time string. * Text can be quoted using single quotes (<code>'</code>) to avoid * interpretation. * <code>"''"</code> represents a single quote. * All other characters are not interpreted; they're simply copied into the * output string during formatting or matched against the input string * during parsing. * <p> * The following pattern letters are defined (all other characters from * <code>'A'</code> to <code>'Z'</code> and from <code>'a'</code> to * <code>'z'</code> are reserved): * <blockquote> * <table border=0 cellspacing=3 cellpadding=0 summary="Chart shows pattern letters, date/time component, presentation, and examples."> * <tr style="background-color: rgb(204, 204, 255);"> * <th align=left>Letter * <th align=left>Date or Time Component * <th align=left>Presentation * <th align=left>Examples * <tr> * <td><code>G</code> * <td>Era designator * <td><a href="#text">Text</a> * <td><code>AD</code> * <tr style="background-color: rgb(238, 238, 255);"> * <td><code>y</code> * <td>Year * <td><a href="#year">Year</a> * <td><code>1996</code>; <code>96</code> * <tr> * <td><code>Y</code> * <td>Week year * <td><a href="#year">Year</a> * <td><code>2009</code>; <code>09</code> * <tr style="background-color: rgb(238, 238, 255);"> * <td><code>M</code> * <td>Month in year (context sensitive) * <td><a href="#month">Month</a> * <td><code>July</code>; <code>Jul</code>; <code>07</code> * <tr> * <td><code>L</code> * <td>Month in year (standalone form) * <td><a href="#month">Month</a> * <td><code>July</code>; <code>Jul</code>; <code>07</code> * <tr style="background-color: rgb(238, 238, 255);"> * <td><code>w</code> * <td>Week in year * <td><a href="#number">Number</a> * <td><code>27</code> * <tr> * <td><code>W</code> * <td>Week in month * <td><a href="#number">Number</a> * <td><code>2</code> * <tr style="background-color: rgb(238, 238, 255);"> * <td><code>D</code> * <td>Day in year * <td><a href="#number">Number</a> * <td><code>189</code> * <tr> * <td><code>d</code> * <td>Day in month * <td><a href="#number">Number</a> * <td><code>10</code> * <tr style="background-color: rgb(238, 238, 255);"> * <td><code>F</code> * <td>Day of week in month * <td><a href="#number">Number</a> * <td><code>2</code> * <tr> * <td><code>E</code> * <td>Day name in week * <td><a href="#text">Text</a> * <td><code>Tuesday</code>; <code>Tue</code> * <tr style="background-color: rgb(238, 238, 255);"> * <td><code>u</code> * <td>Day number of week (1 = Monday, ..., 7 = Sunday) * <td><a href="#number">Number</a> * <td><code>1</code> * <tr> * <td><code>a</code> * <td>Am/pm marker * <td><a href="#text">Text</a> * <td><code>PM</code> * <tr style="background-color: rgb(238, 238, 255);"> * <td><code>H</code> * <td>Hour in day (0-23) * <td><a href="#number">Number</a> * <td><code>0</code> * <tr> * <td><code>k</code> * <td>Hour in day (1-24) * <td><a href="#number">Number</a> * <td><code>24</code> * <tr style="background-color: rgb(238, 238, 255);"> * <td><code>K</code> * <td>Hour in am/pm (0-11) * <td><a href="#number">Number</a> * <td><code>0</code> * <tr> * <td><code>h</code> * <td>Hour in am/pm (1-12) * <td><a href="#number">Number</a> * <td><code>12</code> * <tr style="background-color: rgb(238, 238, 255);"> * <td><code>m</code> * <td>Minute in hour * <td><a href="#number">Number</a> * <td><code>30</code> * <tr> * <td><code>s</code> * <td>Second in minute * <td><a href="#number">Number</a> * <td><code>55</code> * <tr style="background-color: rgb(238, 238, 255);"> * <td><code>S</code> * <td>Millisecond * <td><a href="#number">Number</a> * <td><code>978</code> * <tr> * <td><code>z</code> * <td>Time zone * <td><a href="#timezone">General time zone</a> * <td><code>Pacific Standard Time</code>; <code>PST</code>; <code>GMT-08:00</code> * <tr style="background-color: rgb(238, 238, 255);"> * <td><code>Z</code> * <td>Time zone * <td><a href="#rfc822timezone">RFC 822 time zone</a> * <td><code>-0800</code> * <tr> * <td><code>X</code> * <td>Time zone * <td><a href="#iso8601timezone">ISO 8601 time zone</a> * <td><code>-08</code>; <code>-0800</code>; <code>-08:00</code> * </table> * </blockquote> * Pattern letters are usually repeated, as their number determines the * exact presentation: * <ul> * <li><strong><a name="text">Text:</a></strong> * For formatting, if the number of pattern letters is 4 or more, * the full form is used; otherwise a short or abbreviated form * is used if available. * For parsing, both forms are accepted, independent of the number * of pattern letters.<br><br></li> * <li><strong><a name="number">Number:</a></strong> * For formatting, the number of pattern letters is the minimum * number of digits, and shorter numbers are zero-padded to this amount. * For parsing, the number of pattern letters is ignored unless * it's needed to separate two adjacent fields.<br><br></li> * <li><strong><a name="year">Year:</a></strong> * If the formatter's {@link #getCalendar() Calendar} is the Gregorian * calendar, the following rules are applied.<br> * <ul> * <li>For formatting, if the number of pattern letters is 2, the year * is truncated to 2 digits; otherwise it is interpreted as a * <a href="#number">number</a>. * <li>For parsing, if the number of pattern letters is more than 2, * the year is interpreted literally, regardless of the number of * digits. So using the pattern "MM/dd/yyyy", "01/11/12" parses to * Jan 11, 12 A.D. * <li>For parsing with the abbreviated year pattern ("y" or "yy"), * <code>SimpleDateFormat</code> must interpret the abbreviated year * relative to some century. It does this by adjusting dates to be * within 80 years before and 20 years after the time the <code>SimpleDateFormat</code> * instance is created. For example, using a pattern of "MM/dd/yy" and a * <code>SimpleDateFormat</code> instance created on Jan 1, 1997, the string * "01/11/12" would be interpreted as Jan 11, 2012 while the string "05/04/64" * would be interpreted as May 4, 1964. * During parsing, only strings consisting of exactly two digits, as defined by * {@link Character#isDigit(char)}, will be parsed into the default century. * Any other numeric string, such as a one digit string, a three or more digit * string, or a two digit string that isn't all digits (for example, "-1"), is * interpreted literally. So "01/02/3" or "01/02/003" are parsed, using the * same pattern, as Jan 2, 3 AD. Likewise, "01/02/-3" is parsed as Jan 2, 4 BC. * </ul> * Otherwise, calendar system specific forms are applied. * For both formatting and parsing, if the number of pattern * letters is 4 or more, a calendar specific {@linkplain * Calendar#LONG long form} is used. Otherwise, a calendar * specific {@linkplain Calendar#SHORT short or abbreviated form} * is used.<br> * <br> * If week year {@code 'Y'} is specified and the {@linkplain * #getCalendar() calendar} doesn't support any <a * href="../util/GregorianCalendar.html#week_year"> week * years</a>, the calendar year ({@code 'y'}) is used instead. The * support of week years can be tested with a call to {@link * DateFormat#getCalendar() getCalendar()}.{@link * java.util.Calendar#isWeekDateSupported() * isWeekDateSupported()}.<br><br></li> * <li><strong><a name="month">Month:</a></strong> * If the number of pattern letters is 3 or more, the month is * interpreted as <a href="#text">text</a>; otherwise, * it is interpreted as a <a href="#number">number</a>.<br> * <ul> * <li>Letter <em>M</em> produces context-sensitive month names, such as the * embedded form of names. If a {@code DateFormatSymbols} has been set * explicitly with constructor {@link #SimpleDateFormat(String, * DateFormatSymbols)} or method {@link * #setDateFormatSymbols(DateFormatSymbols)}, the month names given by * the {@code DateFormatSymbols} are used.</li> * <li>Letter <em>L</em> produces the standalone form of month names.</li> * </ul> * <br></li> * <li><strong><a name="timezone">General time zone:</a></strong> * Time zones are interpreted as <a href="#text">text</a> if they have * names. For time zones representing a GMT offset value, the * following syntax is used: * <pre> * <a name="GMTOffsetTimeZone"><i>GMTOffsetTimeZone:</i></a> * <code>GMT</code> <i>Sign</i> <i>Hours</i> <code>:</code> <i>Minutes</i> * <i>Sign:</i> one of * <code>+ -</code> * <i>Hours:</i> * <i>Digit</i> * <i>Digit</i> <i>Digit</i> * <i>Minutes:</i> * <i>Digit</i> <i>Digit</i> * <i>Digit:</i> one of * <code>0 1 2 3 4 5 6 7 8 9</code></pre> * <i>Hours</i> must be between 0 and 23, and <i>Minutes</i> must be between * 00 and 59. The format is locale independent and digits must be taken * from the Basic Latin block of the Unicode standard. * <p>For parsing, <a href="#rfc822timezone">RFC 822 time zones</a> are also * accepted.<br><br></li> * <li><strong><a name="rfc822timezone">RFC 822 time zone:</a></strong> * For formatting, the RFC 822 4-digit time zone format is used: * * <pre> * <i>RFC822TimeZone:</i> * <i>Sign</i> <i>TwoDigitHours</i> <i>Minutes</i> * <i>TwoDigitHours:</i> * <i>Digit Digit</i></pre> * <i>TwoDigitHours</i> must be between 00 and 23. Other definitions * are as for <a href="#timezone">general time zones</a>. * * <p>For parsing, <a href="#timezone">general time zones</a> are also * accepted. * <li><strong><a name="iso8601timezone">ISO 8601 Time zone:</a></strong> * The number of pattern letters designates the format for both formatting * and parsing as follows: * <pre> * <i>ISO8601TimeZone:</i> * <i>OneLetterISO8601TimeZone</i> * <i>TwoLetterISO8601TimeZone</i> * <i>ThreeLetterISO8601TimeZone</i> * <i>OneLetterISO8601TimeZone:</i> * <i>Sign</i> <i>TwoDigitHours</i> * {@code Z} * <i>TwoLetterISO8601TimeZone:</i> * <i>Sign</i> <i>TwoDigitHours</i> <i>Minutes</i> * {@code Z} * <i>ThreeLetterISO8601TimeZone:</i> * <i>Sign</i> <i>TwoDigitHours</i> {@code :} <i>Minutes</i> * {@code Z}</pre> * Other definitions are as for <a href="#timezone">general time zones</a> or * <a href="#rfc822timezone">RFC 822 time zones</a>. * * <p>For formatting, if the offset value from GMT is 0, {@code "Z"} is * produced. If the number of pattern letters is 1, any fraction of an hour * is ignored. For example, if the pattern is {@code "X"} and the time zone is * {@code "GMT+05:30"}, {@code "+05"} is produced. * * <p>For parsing, {@code "Z"} is parsed as the UTC time zone designator. * <a href="#timezone">General time zones</a> are <em>not</em> accepted. * * <p>If the number of pattern letters is 4 or more, {@link * IllegalArgumentException} is thrown when constructing a {@code * SimpleDateFormat} or {@linkplain #applyPattern(String) applying a * pattern}. * </ul> * <code>SimpleDateFormat</code> also supports <em>localized date and time * pattern</em> strings. In these strings, the pattern letters described above * may be replaced with other, locale dependent, pattern letters. * <code>SimpleDateFormat</code> does not deal with the localization of text * other than the pattern letters; that's up to the client of the class. * * <h4>Examples</h4> * * The following examples show how date and time patterns are interpreted in * the U.S. locale. The given date and time are 2001-07-04 12:08:56 local time * in the U.S. Pacific Time time zone. * <blockquote> * <table border=0 cellspacing=3 cellpadding=0 summary="Examples of date and time patterns interpreted in the U.S. locale"> * <tr style="background-color: rgb(204, 204, 255);"> * <th align=left>Date and Time Pattern * <th align=left>Result * <tr> * <td><code>"yyyy.MM.dd G 'at' HH:mm:ss z"</code> * <td><code>2001.07.04 AD at 12:08:56 PDT</code> * <tr style="background-color: rgb(238, 238, 255);"> * <td><code>"EEE, MMM d, ''yy"</code> * <td><code>Wed, Jul 4, '01</code> * <tr> * <td><code>"h:mm a"</code> * <td><code>12:08 PM</code> * <tr style="background-color: rgb(238, 238, 255);"> * <td><code>"hh 'o''clock' a, zzzz"</code> * <td><code>12 o'clock PM, Pacific Daylight Time</code> * <tr> * <td><code>"K:mm a, z"</code> * <td><code>0:08 PM, PDT</code> * <tr style="background-color: rgb(238, 238, 255);"> * <td><code>"yyyyy.MMMMM.dd GGG hh:mm aaa"</code> * <td><code>02001.July.04 AD 12:08 PM</code> * <tr> * <td><code>"EEE, d MMM yyyy HH:mm:ss Z"</code> * <td><code>Wed, 4 Jul 2001 12:08:56 -0700</code> * <tr style="background-color: rgb(238, 238, 255);"> * <td><code>"yyMMddHHmmssZ"</code> * <td><code>010704120856-0700</code> * <tr> * <td><code>"yyyy-MM-dd'T'HH:mm:ss.SSSZ"</code> * <td><code>2001-07-04T12:08:56.235-0700</code> * <tr style="background-color: rgb(238, 238, 255);"> * <td><code>"yyyy-MM-dd'T'HH:mm:ss.SSSXXX"</code> * <td><code>2001-07-04T12:08:56.235-07:00</code> * <tr> * <td><code>"YYYY-'W'ww-u"</code> * <td><code>2001-W27-3</code> * </table> * </blockquote> * * <h4><a name="synchronization">Synchronization</a></h4> * * <p> * 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. * * @see <a href="https://docs.oracle.com/javase/tutorial/i18n/format/simpleDateFormat.html">Java Tutorial</a> * @see java.util.Calendar * @see java.util.TimeZone * @see DateFormat * @see DateFormatSymbols * @author Mark Davis, Chen-Lieh Huang, Alan Liu */ public class SimpleDateFormat extends DateFormat {
java.text.SimpleDateFormat