< prev index next >

src/java.base/share/classes/java/text/SimpleDateFormat.java

Print this page




 925 
 926     /**
 927      * Returns the beginning date of the 100-year period 2-digit years are interpreted
 928      * as being within.
 929      *
 930      * @return the start of the 100-year period into which two digit years are
 931      * parsed
 932      * @see #set2DigitYearStart
 933      * @since 1.2
 934      */
 935     public Date get2DigitYearStart() {
 936         return (Date) defaultCenturyStart.clone();
 937     }
 938 
 939     /**
 940      * Formats the given <code>Date</code> into a date/time string and appends
 941      * the result to the given <code>StringBuffer</code>.
 942      *
 943      * @param date the date-time value to be formatted into a date-time string.
 944      * @param toAppendTo where the new date-time text is to be appended.
 945      * @param pos the formatting position. On input: an alignment field,
 946      * if desired. On output: the offsets of the alignment field.











 947      * @return the formatted date-time string.
 948      * @exception NullPointerException if any of the parameters is {@code null}.
 949      */
 950     @Override
 951     public StringBuffer format(Date date, StringBuffer toAppendTo,
 952                                FieldPosition pos)
 953     {
 954         pos.beginIndex = pos.endIndex = 0;
 955         return format(date, toAppendTo, pos.getFieldDelegate());
 956     }
 957 
 958     // Called from Format after creating a FieldDelegate
 959     private StringBuffer format(Date date, StringBuffer toAppendTo,
 960                                 FieldDelegate delegate) {
 961         // Convert input date to time field list
 962         calendar.setTime(date);
 963 
 964         boolean useDateFormatSymbols = useDateFormatSymbols();
 965 
 966         for (int i = 0; i < compiledPattern.length; ) {




 925 
 926     /**
 927      * Returns the beginning date of the 100-year period 2-digit years are interpreted
 928      * as being within.
 929      *
 930      * @return the start of the 100-year period into which two digit years are
 931      * parsed
 932      * @see #set2DigitYearStart
 933      * @since 1.2
 934      */
 935     public Date get2DigitYearStart() {
 936         return (Date) defaultCenturyStart.clone();
 937     }
 938 
 939     /**
 940      * Formats the given <code>Date</code> into a date/time string and appends
 941      * the result to the given <code>StringBuffer</code>.
 942      *
 943      * @param date the date-time value to be formatted into a date-time string.
 944      * @param toAppendTo where the new date-time text is to be appended.
 945      * @param pos keeps track on the position of the field within
 946      * the returned string. For example, given a date-time text
 947      * {@code "1996.07.10 AD at 15:08:56 PDT"}, if the given {@code fieldPosition}
 948      * is {@link DateFormat#YEAR_FIELD}, the begin index and end index of
 949      * {@code fieldPosition} will be set to 0 and 4, respectively.
 950      * Notice that if the same date-time field appears more than once in a
 951      * pattern, the {@code fieldPosition} will be set for the first occurrence
 952      * of that date-time field. For instance, formatting a {@code Date} to the
 953      * date-time string {@code "1 PM PDT (Pacific Daylight Time)"} using the
 954      * pattern {@code "h a z (zzzz)"} and the alignment field
 955      * {@link DateFormat#TIMEZONE_FIELD}, the begin index and end index of
 956      * {@code fieldPosition} will be set to 5 and 8, respectively, for the
 957      * first occurrence of the timezone pattern character {@code 'z'}.
 958      * @return the formatted date-time string.
 959      * @exception NullPointerException if any of the parameters is {@code null}.
 960      */
 961     @Override
 962     public StringBuffer format(Date date, StringBuffer toAppendTo,
 963                                FieldPosition pos)
 964     {
 965         pos.beginIndex = pos.endIndex = 0;
 966         return format(date, toAppendTo, pos.getFieldDelegate());
 967     }
 968 
 969     // Called from Format after creating a FieldDelegate
 970     private StringBuffer format(Date date, StringBuffer toAppendTo,
 971                                 FieldDelegate delegate) {
 972         // Convert input date to time field list
 973         calendar.setTime(date);
 974 
 975         boolean useDateFormatSymbols = useDateFormatSymbols();
 976 
 977         for (int i = 0; i < compiledPattern.length; ) {


< prev index next >