< prev index next >

src/java.base/share/classes/java/time/format/DateTimeFormatter.java

Print this page




 133  * <p>
 134  * The {@link #withChronology withChronology} method returns a new formatter
 135  * that overrides the chronology. If overridden, the date-time value is
 136  * converted to the chronology before formatting. During parsing the date-time
 137  * value is converted to the chronology before it is returned.
 138  * <p>
 139  * The {@link #withZone withZone} method returns a new formatter that overrides
 140  * the zone. If overridden, the date-time value is converted to a ZonedDateTime
 141  * with the requested ZoneId before formatting. During parsing the ZoneId is
 142  * applied before the value is returned.
 143  * <p>
 144  * The {@link #withDecimalStyle withDecimalStyle} method returns a new formatter that
 145  * overrides the {@link DecimalStyle}. The DecimalStyle symbols are used for
 146  * formatting and parsing.
 147  * <p>
 148  * Some applications may need to use the older {@link Format java.text.Format}
 149  * class for formatting. The {@link #toFormat()} method returns an
 150  * implementation of {@code java.text.Format}.
 151  *
 152  * <h3 id="predefined">Predefined Formatters</h3>
 153  * <table summary="Predefined Formatters" cellpadding="2" cellspacing="3" border="0" >

 154  * <thead>
 155  * <tr class="tableSubHeadingColor">
 156  * <th class="colFirst" style="text-align:left">Formatter</th>
 157  * <th class="colFirst" style="text-align:left">Description</th>
 158  * <th class="colLast" style="text-align:left">Example</th>
 159  * </tr>
 160  * </thead>
 161  * <tbody>
 162  * <tr class="rowColor">
 163  * <td>{@link #ofLocalizedDate ofLocalizedDate(dateStyle)} </td>
 164  * <td> Formatter with date style from the locale </td>
 165  * <td> '2011-12-03'</td>
 166  * </tr>
 167  * <tr class="altColor">
 168  * <td> {@link #ofLocalizedTime ofLocalizedTime(timeStyle)} </td>
 169  * <td> Formatter with time style from the locale </td>
 170  * <td> '10:15:30'</td>
 171  * </tr>
 172  * <tr class="rowColor">
 173  * <td> {@link #ofLocalizedDateTime ofLocalizedDateTime(dateTimeStyle)} </td>
 174  * <td> Formatter with a style for date and time from the locale</td>
 175  * <td> '3 Jun 2008 11:05:30'</td>
 176  * </tr>
 177  * <tr class="altColor">
 178  * <td> {@link #ofLocalizedDateTime ofLocalizedDateTime(dateStyle,timeStyle)}
 179  * </td>
 180  * <td> Formatter with date and time styles from the locale </td>
 181  * <td> '3 Jun 2008 11:05'</td>
 182  * </tr>
 183  * <tr class="rowColor">
 184  * <td> {@link #BASIC_ISO_DATE}</td>
 185  * <td>Basic ISO date </td> <td>'20111203'</td>
 186  * </tr>
 187  * <tr class="altColor">
 188  * <td> {@link #ISO_LOCAL_DATE}</td>
 189  * <td> ISO Local Date </td>
 190  * <td>'2011-12-03'</td>
 191  * </tr>
 192  * <tr class="rowColor">
 193  * <td> {@link #ISO_OFFSET_DATE}</td>
 194  * <td> ISO Date with offset </td>
 195  * <td>'2011-12-03+01:00'</td>
 196  * </tr>
 197  * <tr class="altColor">
 198  * <td> {@link #ISO_DATE}</td>
 199  * <td> ISO Date with or without offset </td>
 200  * <td> '2011-12-03+01:00'; '2011-12-03'</td>
 201  * </tr>
 202  * <tr class="rowColor">
 203  * <td> {@link #ISO_LOCAL_TIME}</td>
 204  * <td> Time without offset </td>
 205  * <td>'10:15:30'</td>
 206  * </tr>
 207  * <tr class="altColor">
 208  * <td> {@link #ISO_OFFSET_TIME}</td>
 209  * <td> Time with offset </td>
 210  * <td>'10:15:30+01:00'</td>
 211  * </tr>
 212  * <tr class="rowColor">
 213  * <td> {@link #ISO_TIME}</td>
 214  * <td> Time with or without offset </td>
 215  * <td>'10:15:30+01:00'; '10:15:30'</td>
 216  * </tr>
 217  * <tr class="altColor">
 218  * <td> {@link #ISO_LOCAL_DATE_TIME}</td>
 219  * <td> ISO Local Date and Time </td>
 220  * <td>'2011-12-03T10:15:30'</td>
 221  * </tr>
 222  * <tr class="rowColor">
 223  * <td> {@link #ISO_OFFSET_DATE_TIME}</td>
 224  * <td> Date Time with Offset
 225  * </td><td>2011-12-03T10:15:30+01:00'</td>
 226  * </tr>
 227  * <tr class="altColor">
 228  * <td> {@link #ISO_ZONED_DATE_TIME}</td>
 229  * <td> Zoned Date Time </td>
 230  * <td>'2011-12-03T10:15:30+01:00[Europe/Paris]'</td>
 231  * </tr>
 232  * <tr class="rowColor">
 233  * <td> {@link #ISO_DATE_TIME}</td>
 234  * <td> Date and time with ZoneId </td>
 235  * <td>'2011-12-03T10:15:30+01:00[Europe/Paris]'</td>
 236  * </tr>
 237  * <tr class="altColor">
 238  * <td> {@link #ISO_ORDINAL_DATE}</td>
 239  * <td> Year and day of year </td>
 240  * <td>'2012-337'</td>
 241  * </tr>
 242  * <tr class="rowColor">
 243  * <td> {@link #ISO_WEEK_DATE}</td>
 244  * <td> Year and Week </td>
 245  * <td>2012-W48-6'</td></tr>
 246  * <tr class="altColor">
 247  * <td> {@link #ISO_INSTANT}</td>
 248  * <td> Date and Time of an Instant </td>
 249  * <td>'2011-12-03T10:15:30Z' </td>
 250  * </tr>
 251  * <tr class="rowColor">
 252  * <td> {@link #RFC_1123_DATE_TIME}</td>
 253  * <td> RFC 1123 / RFC 822 </td>
 254  * <td>'Tue, 3 Jun 2008 11:05:30 GMT'</td>
 255  * </tr>
 256  * </tbody>
 257  * </table>
 258  *
 259  * <h3 id="patterns">Patterns for Formatting and Parsing</h3>
 260  * Patterns are based on a simple sequence of letters and symbols.
 261  * A pattern is used to create a Formatter using the
 262  * {@link #ofPattern(String)} and {@link #ofPattern(String, Locale)} methods.
 263  * For example,
 264  * {@code "d MMM uuuu"} will format 2011-12-03 as '3&nbsp;Dec&nbsp;2011'.
 265  * A formatter created from a pattern can be used as many times as necessary,
 266  * it is immutable and is thread-safe.
 267  * <p>
 268  * For example:
 269  * <blockquote><pre>
 270  *  LocalDate date = LocalDate.now();
 271  *  DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy MM dd");




 133  * <p>
 134  * The {@link #withChronology withChronology} method returns a new formatter
 135  * that overrides the chronology. If overridden, the date-time value is
 136  * converted to the chronology before formatting. During parsing the date-time
 137  * value is converted to the chronology before it is returned.
 138  * <p>
 139  * The {@link #withZone withZone} method returns a new formatter that overrides
 140  * the zone. If overridden, the date-time value is converted to a ZonedDateTime
 141  * with the requested ZoneId before formatting. During parsing the ZoneId is
 142  * applied before the value is returned.
 143  * <p>
 144  * The {@link #withDecimalStyle withDecimalStyle} method returns a new formatter that
 145  * overrides the {@link DecimalStyle}. The DecimalStyle symbols are used for
 146  * formatting and parsing.
 147  * <p>
 148  * Some applications may need to use the older {@link Format java.text.Format}
 149  * class for formatting. The {@link #toFormat()} method returns an
 150  * implementation of {@code java.text.Format}.
 151  *
 152  * <h3 id="predefined">Predefined Formatters</h3>
 153  * <table class="striped">
 154  * <caption>Predefined Formatters</caption>
 155  * <thead>
 156  * <tr>
 157  * <th style="text-align:left">Formatter</th>
 158  * <th style="text-align:left">Description</th>
 159  * <th style="text-align:left">Example</th>
 160  * </tr>
 161  * </thead>
 162  * <tbody>
 163  * <tr>
 164  * <td>{@link #ofLocalizedDate ofLocalizedDate(dateStyle)} </td>
 165  * <td> Formatter with date style from the locale </td>
 166  * <td> '2011-12-03'</td>
 167  * </tr>
 168  * <tr>
 169  * <td> {@link #ofLocalizedTime ofLocalizedTime(timeStyle)} </td>
 170  * <td> Formatter with time style from the locale </td>
 171  * <td> '10:15:30'</td>
 172  * </tr>
 173  * <tr>
 174  * <td> {@link #ofLocalizedDateTime ofLocalizedDateTime(dateTimeStyle)} </td>
 175  * <td> Formatter with a style for date and time from the locale</td>
 176  * <td> '3 Jun 2008 11:05:30'</td>
 177  * </tr>
 178  * <tr>
 179  * <td> {@link #ofLocalizedDateTime ofLocalizedDateTime(dateStyle,timeStyle)}
 180  * </td>
 181  * <td> Formatter with date and time styles from the locale </td>
 182  * <td> '3 Jun 2008 11:05'</td>
 183  * </tr>
 184  * <tr>
 185  * <td> {@link #BASIC_ISO_DATE}</td>
 186  * <td>Basic ISO date </td> <td>'20111203'</td>
 187  * </tr>
 188  * <tr>
 189  * <td> {@link #ISO_LOCAL_DATE}</td>
 190  * <td> ISO Local Date </td>
 191  * <td>'2011-12-03'</td>
 192  * </tr>
 193  * <tr>
 194  * <td> {@link #ISO_OFFSET_DATE}</td>
 195  * <td> ISO Date with offset </td>
 196  * <td>'2011-12-03+01:00'</td>
 197  * </tr>
 198  * <tr>
 199  * <td> {@link #ISO_DATE}</td>
 200  * <td> ISO Date with or without offset </td>
 201  * <td> '2011-12-03+01:00'; '2011-12-03'</td>
 202  * </tr>
 203  * <tr>
 204  * <td> {@link #ISO_LOCAL_TIME}</td>
 205  * <td> Time without offset </td>
 206  * <td>'10:15:30'</td>
 207  * </tr>
 208  * <tr>
 209  * <td> {@link #ISO_OFFSET_TIME}</td>
 210  * <td> Time with offset </td>
 211  * <td>'10:15:30+01:00'</td>
 212  * </tr>
 213  * <tr>
 214  * <td> {@link #ISO_TIME}</td>
 215  * <td> Time with or without offset </td>
 216  * <td>'10:15:30+01:00'; '10:15:30'</td>
 217  * </tr>
 218  * <tr>
 219  * <td> {@link #ISO_LOCAL_DATE_TIME}</td>
 220  * <td> ISO Local Date and Time </td>
 221  * <td>'2011-12-03T10:15:30'</td>
 222  * </tr>
 223  * <tr>
 224  * <td> {@link #ISO_OFFSET_DATE_TIME}</td>
 225  * <td> Date Time with Offset
 226  * </td><td>2011-12-03T10:15:30+01:00'</td>
 227  * </tr>
 228  * <tr>
 229  * <td> {@link #ISO_ZONED_DATE_TIME}</td>
 230  * <td> Zoned Date Time </td>
 231  * <td>'2011-12-03T10:15:30+01:00[Europe/Paris]'</td>
 232  * </tr>
 233  * <tr>
 234  * <td> {@link #ISO_DATE_TIME}</td>
 235  * <td> Date and time with ZoneId </td>
 236  * <td>'2011-12-03T10:15:30+01:00[Europe/Paris]'</td>
 237  * </tr>
 238  * <tr>
 239  * <td> {@link #ISO_ORDINAL_DATE}</td>
 240  * <td> Year and day of year </td>
 241  * <td>'2012-337'</td>
 242  * </tr>
 243  * <tr>
 244  * <td> {@link #ISO_WEEK_DATE}</td>
 245  * <td> Year and Week </td>
 246  * <td>2012-W48-6'</td></tr>
 247  * <tr>
 248  * <td> {@link #ISO_INSTANT}</td>
 249  * <td> Date and Time of an Instant </td>
 250  * <td>'2011-12-03T10:15:30Z' </td>
 251  * </tr>
 252  * <tr>
 253  * <td> {@link #RFC_1123_DATE_TIME}</td>
 254  * <td> RFC 1123 / RFC 822 </td>
 255  * <td>'Tue, 3 Jun 2008 11:05:30 GMT'</td>
 256  * </tr>
 257  * </tbody>
 258  * </table>
 259  *
 260  * <h3 id="patterns">Patterns for Formatting and Parsing</h3>
 261  * Patterns are based on a simple sequence of letters and symbols.
 262  * A pattern is used to create a Formatter using the
 263  * {@link #ofPattern(String)} and {@link #ofPattern(String, Locale)} methods.
 264  * For example,
 265  * {@code "d MMM uuuu"} will format 2011-12-03 as '3&nbsp;Dec&nbsp;2011'.
 266  * A formatter created from a pattern can be used as many times as necessary,
 267  * it is immutable and is thread-safe.
 268  * <p>
 269  * For example:
 270  * <blockquote><pre>
 271  *  LocalDate date = LocalDate.now();
 272  *  DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy MM dd");


< prev index next >