< prev index next >

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

Print this page


   1 /*
   2  * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 267  * <p>
 268  * For example:
 269  * <blockquote><pre>
 270  *  LocalDate date = LocalDate.now();
 271  *  DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy MM dd");
 272  *  String text = date.format(formatter);
 273  *  LocalDate parsedDate = LocalDate.parse(text, formatter);
 274  * </pre></blockquote>
 275  * <p>
 276  * All letters 'A' to 'Z' and 'a' to 'z' are reserved as pattern letters. The
 277  * following pattern letters are defined:
 278  * <pre>
 279  *  Symbol  Meaning                     Presentation      Examples
 280  *  ------  -------                     ------------      -------
 281  *   G       era                         text              AD; Anno Domini; A
 282  *   u       year                        year              2004; 04
 283  *   y       year-of-era                 year              2004; 04
 284  *   D       day-of-year                 number            189
 285  *   M/L     month-of-year               number/text       7; 07; Jul; July; J
 286  *   d       day-of-month                number            10

 287  *
 288  *   Q/q     quarter-of-year             number/text       3; 03; Q3; 3rd quarter
 289  *   Y       week-based-year             year              1996; 96
 290  *   w       week-of-week-based-year     number            27
 291  *   W       week-of-month               number            4
 292  *   E       day-of-week                 text              Tue; Tuesday; T
 293  *   e/c     localized day-of-week       number/text       2; 02; Tue; Tuesday; T
 294  *   F       week-of-month               number            3
 295  *
 296  *   a       am-pm-of-day                text              PM
 297  *   h       clock-hour-of-am-pm (1-12)  number            12
 298  *   K       hour-of-am-pm (0-11)        number            0
 299  *   k       clock-hour-of-am-pm (1-24)  number            0
 300  *
 301  *   H       hour-of-day (0-23)          number            0
 302  *   m       minute-of-hour              number            30
 303  *   s       second-of-minute            number            55
 304  *   S       fraction-of-second          fraction          978
 305  *   A       milli-of-day                number            1234
 306  *   n       nano-of-second              number            987654321
 307  *   N       nano-of-day                 number            1234000000
 308  *
 309  *   V       time-zone ID                zone-id           America/Los_Angeles; Z; -08:30
 310  *   z       time-zone name              zone-name         Pacific Standard Time; PST
 311  *   O       localized zone-offset       offset-O          GMT+8; GMT+08:00; UTC-08:00;
 312  *   X       zone-offset 'Z' for zero    offset-X          Z; -08; -0830; -08:30; -083015; -08:30:15;
 313  *   x       zone-offset                 offset-x          +0000; -08; -0830; -08:30; -083015; -08:30:15;
 314  *   Z       zone-offset                 offset-Z          +0000; -0800; -08:00;
 315  *
 316  *   p       pad next                    pad modifier      1
 317  *
 318  *   '       escape for text             delimiter
 319  *   ''      single quote                literal           '
 320  *   [       optional section start
 321  *   ]       optional section end
 322  *   #       reserved for future use
 323  *   {       reserved for future use
 324  *   }       reserved for future use
 325  * </pre>
 326  * <p>
 327  * The count of pattern letters determines the format.
 328  * <p>
 329  * <b>Text</b>: The text style is determined based on the number of pattern
 330  * letters used. Less than 4 pattern letters will use the
 331  * {@link TextStyle#SHORT short form}. Exactly 4 pattern letters will use the
 332  * {@link TextStyle#FULL full form}. Exactly 5 pattern letters will use the
 333  * {@link TextStyle#NARROW narrow form}.
 334  * Pattern letters 'L', 'c', and 'q' specify the stand-alone form of the text styles.


   1 /*
   2  * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 267  * <p>
 268  * For example:
 269  * <blockquote><pre>
 270  *  LocalDate date = LocalDate.now();
 271  *  DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy MM dd");
 272  *  String text = date.format(formatter);
 273  *  LocalDate parsedDate = LocalDate.parse(text, formatter);
 274  * </pre></blockquote>
 275  * <p>
 276  * All letters 'A' to 'Z' and 'a' to 'z' are reserved as pattern letters. The
 277  * following pattern letters are defined:
 278  * <pre>
 279  *  Symbol  Meaning                     Presentation      Examples
 280  *  ------  -------                     ------------      -------
 281  *   G       era                         text              AD; Anno Domini; A
 282  *   u       year                        year              2004; 04
 283  *   y       year-of-era                 year              2004; 04
 284  *   D       day-of-year                 number            189
 285  *   M/L     month-of-year               number/text       7; 07; Jul; July; J
 286  *   d       day-of-month                number            10
 287  *   g       modified-julian-day         number            2451334
 288  *
 289  *   Q/q     quarter-of-year             number/text       3; 03; Q3; 3rd quarter
 290  *   Y       week-based-year             year              1996; 96
 291  *   w       week-of-week-based-year     number            27
 292  *   W       week-of-month               number            4
 293  *   E       day-of-week                 text              Tue; Tuesday; T
 294  *   e/c     localized day-of-week       number/text       2; 02; Tue; Tuesday; T
 295  *   F       week-of-month               number            3
 296  *
 297  *   a       am-pm-of-day                text              PM
 298  *   h       clock-hour-of-am-pm (1-12)  number            12
 299  *   K       hour-of-am-pm (0-11)        number            0
 300  *   k       clock-hour-of-am-pm (1-24)  number            0
 301  *
 302  *   H       hour-of-day (0-23)          number            0
 303  *   m       minute-of-hour              number            30
 304  *   s       second-of-minute            number            55
 305  *   S       fraction-of-second          fraction          978
 306  *   A       milli-of-day                number            1234
 307  *   n       nano-of-second              number            987654321
 308  *   N       nano-of-day                 number            1234000000
 309  *
 310  *   V       time-zone ID                zone-id           America/Los_Angeles; Z; -08:30
 311  *   z       time-zone name              zone-name         Pacific Standard Time; PST
 312  *   O       localized zone-offset       offset-O          GMT+8; GMT+08:00; UTC-08:00
 313  *   X       zone-offset 'Z' for zero    offset-X          Z; -08; -0830; -08:30; -083015; -08:30:15
 314  *   x       zone-offset                 offset-x          +0000; -08; -0830; -08:30; -083015; -08:30:15
 315  *   Z       zone-offset                 offset-Z          +0000; -0800; -08:00
 316  *
 317  *   p       pad next                    pad modifier      1
 318  *
 319  *   '       escape for text             delimiter
 320  *   ''      single quote                literal           '
 321  *   [       optional section start
 322  *   ]       optional section end
 323  *   #       reserved for future use
 324  *   {       reserved for future use
 325  *   }       reserved for future use
 326  * </pre>
 327  * <p>
 328  * The count of pattern letters determines the format.
 329  * <p>
 330  * <b>Text</b>: The text style is determined based on the number of pattern
 331  * letters used. Less than 4 pattern letters will use the
 332  * {@link TextStyle#SHORT short form}. Exactly 4 pattern letters will use the
 333  * {@link TextStyle#FULL full form}. Exactly 5 pattern letters will use the
 334  * {@link TextStyle#NARROW narrow form}.
 335  * Pattern letters 'L', 'c', and 'q' specify the stand-alone form of the text styles.


< prev index next >