コード例 #1
0
 /**
  * Creates a date formatter using the specified non-localized pattern, with the default
  * DateFormatSymbols for the given locale.
  *
  * @param pattern the non-localized pattern to use.
  * @param locale the locale to use for the formatting symbols.
  * @throws NullPointerException if the pattern is null.
  * @throws IllegalArgumentException if the pattern is invalid.
  */
 public SimpleDateFormat(String pattern, Locale locale) {
   super();
   calendar = new GregorianCalendar(locale);
   computeCenturyStart();
   tokens = new ArrayList();
   formatData = new DateFormatSymbols(locale);
   compileFormat(pattern);
   this.pattern = pattern;
   numberFormat = NumberFormat.getInstance(locale);
   numberFormat.setGroupingUsed(false);
   numberFormat.setParseIntegerOnly(true);
   numberFormat.setMaximumFractionDigits(0);
 }
コード例 #2
0
 /**
  * Creates a date formatter using the specified non-localized pattern. The specified
  * DateFormatSymbols will be used when formatting.
  *
  * @param pattern the non-localized pattern to use.
  * @param formatData the formatting symbols to use.
  * @throws NullPointerException if the pattern or formatData is null.
  * @throws IllegalArgumentException if the pattern is invalid.
  */
 public SimpleDateFormat(String pattern, DateFormatSymbols formatData) {
   super();
   calendar = new GregorianCalendar();
   computeCenturyStart();
   tokens = new ArrayList();
   if (formatData == null) throw new NullPointerException("formatData");
   this.formatData = formatData;
   compileFormat(pattern);
   this.pattern = pattern;
   numberFormat = NumberFormat.getInstance();
   numberFormat.setGroupingUsed(false);
   numberFormat.setParseIntegerOnly(true);
   numberFormat.setMaximumFractionDigits(0);
 }
コード例 #3
0
  /**
   * Reads the serialized version of this object. If the serialized data is only version 0, then the
   * date for the start of the century for interpreting two digit years is computed. The pattern is
   * parsed and compiled following the process of reading in the serialized data.
   *
   * @param stream the object stream to read the data from.
   * @throws IOException if an I/O error occurs.
   * @throws ClassNotFoundException if the class of the serialized data could not be found.
   * @throws InvalidObjectException if the pattern is invalid.
   */
  private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
    stream.defaultReadObject();
    if (serialVersionOnStream < 1) {
      computeCenturyStart();
      serialVersionOnStream = 1;
    } else
      // Ensure that defaultCentury gets set.
      set2DigitYearStart(defaultCenturyStart);

    // Set up items normally taken care of by the constructor.
    tokens = new ArrayList();
    try {
      compileFormat(pattern);
    } catch (IllegalArgumentException e) {
      throw new InvalidObjectException("The stream pattern was invalid.");
    }
  }
コード例 #4
0
 /** Constructs a SimpleDateFormat using the default pattern for the default locale. */
 public SimpleDateFormat() {
   /*
    * There does not appear to be a standard API for determining
    * what the default pattern for a locale is, so use package-scope
    * variables in DateFormatSymbols to encapsulate this.
    */
   super();
   Locale locale = Locale.getDefault();
   calendar = new GregorianCalendar(locale);
   computeCenturyStart();
   tokens = new ArrayList();
   formatData = new DateFormatSymbols(locale);
   pattern = (formatData.dateFormats[DEFAULT] + ' ' + formatData.timeFormats[DEFAULT]);
   compileFormat(pattern);
   numberFormat = NumberFormat.getInstance(locale);
   numberFormat.setGroupingUsed(false);
   numberFormat.setParseIntegerOnly(true);
   numberFormat.setMaximumFractionDigits(0);
 }