java.text.DateFormat.clone()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(7.6k)|赞(0)|评价(0)|浏览(233)

本文整理了Java中java.text.DateFormat.clone()方法的一些代码示例,展示了DateFormat.clone()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。DateFormat.clone()方法的具体详情如下:
包路径:java.text.DateFormat
类名称:DateFormat
方法名:clone

DateFormat.clone介绍

[英]Returns a new instance of DateFormat with the same properties.
[中]返回具有相同属性的DateFormat的新实例。

代码示例

代码示例来源:origin: org.codehaus.jackson/jackson-mapper-asl

protected Date parseAsRFC1123(String dateStr, ParsePosition pos)
{
  if (_formatRFC1123 == null) {
    _formatRFC1123 = (DateFormat) DATE_FORMAT_RFC1123.clone();
  }
  return _formatRFC1123.parse(dateStr, pos);
}

代码示例来源:origin: org.codehaus.jackson/jackson-mapper-asl

/**
 * Method for getting a non-shared DateFormat instance
 * that uses specified timezone and can handle simple ISO-8601
 * compliant date format.
 */
public static DateFormat getISO8601Format(TimeZone tz) {
  DateFormat df = (DateFormat) DATE_FORMAT_ISO8601.clone();
  df.setTimeZone(tz);
  return df;
}

代码示例来源:origin: org.codehaus.jackson/jackson-mapper-asl

@Override
public StringBuffer format(Date date, StringBuffer toAppendTo,
              FieldPosition fieldPosition)
{
  if (_formatISO8601 == null) {
    _formatISO8601 = (DateFormat) DATE_FORMAT_ISO8601.clone();
  }
  return _formatISO8601.format(date, toAppendTo, fieldPosition);
}

代码示例来源:origin: org.codehaus.jackson/jackson-mapper-asl

/**
 * Method for getting a non-shared DateFormat instance
 * that uses specific timezone and can handle RFC-1123
 * compliant date format.
 */
public static DateFormat getRFC1123Format(TimeZone tz)
{
  DateFormat df = (DateFormat) DATE_FORMAT_RFC1123.clone();
  df.setTimeZone(tz);
  return df;
}

代码示例来源:origin: nutzam/nutz

/**
 * 以给定的时间格式来安全的解析时间字符串,并返回解析后所对应的时间对象
 * 
 * @param fmt
 *            时间格式
 * @param s
 *            日期时间字符串
 * @return 该时间字符串对应的时间对象
 */
public static Date parse(DateFormat fmt, String s) throws ParseException {
  return ((DateFormat) fmt.clone()).parse(s);
}

代码示例来源:origin: nutzam/nutz

/**
 * 以给定的时间格式来安全的对时间进行格式化,并返回格式化后所对应的字符串
 * 
 * @param fmt
 *            时间格式
 * @param d
 *            时间对象
 * @return 格式化后的字符串
 */
public static String format(DateFormat fmt, Date d) {
  return ((DateFormat) fmt.clone()).format(d);
}

代码示例来源:origin: log4j/log4j

/**
 * @throws java.text.ParseException
 */
public Date parse(String date, String pattern) throws ParseException {
 DateFormat formatter = null;
 formatter = getDateFormatInstance();
 if (formatter instanceof SimpleDateFormat) {
  formatter = (SimpleDateFormat) (formatter.clone());
  ((SimpleDateFormat) formatter).applyPattern(pattern);
 }
 return formatter.parse(date);
}

代码示例来源:origin: log4j/log4j

public String format(Date date, String pattern) {
 DateFormat formatter = null;
 formatter = getDateFormatInstance();
 if (formatter instanceof SimpleDateFormat) {
  formatter = (SimpleDateFormat) (formatter.clone());
  ((SimpleDateFormat) formatter).applyPattern(pattern);
 }
 return formatter.format(date);
}

代码示例来源:origin: prestodb/presto

private DateFormat _force(DateFormat df, TimeZone tz)
  {
    if (df instanceof StdDateFormat) {
      return ((StdDateFormat) df).withTimeZone(tz);
    }
    // we don't know if original format might be shared; better create a clone:
    df = (DateFormat) df.clone();
    df.setTimeZone(tz);
    return df;
  }
}

代码示例来源:origin: redisson/redisson

private DateFormat _force(DateFormat df, TimeZone tz)
  {
    if (df instanceof StdDateFormat) {
      return ((StdDateFormat) df).withTimeZone(tz);
    }
    // we don't know if original format might be shared; better create a clone:
    df = (DateFormat) df.clone();
    df.setTimeZone(tz);
    return df;
  }
}

代码示例来源:origin: prestodb/presto

private final static DateFormat _cloneFormat(DateFormat df, String format,
    TimeZone tz, Locale loc, Boolean lenient)
{
  if (!loc.equals(DEFAULT_LOCALE)) {
    df = new SimpleDateFormat(format, loc);
    df.setTimeZone((tz == null) ? DEFAULT_TIMEZONE : tz);
  } else {
    df = (DateFormat) df.clone();
    if (tz != null) {
      df.setTimeZone(tz);
    }
  }
  if (lenient != null) {
    df.setLenient(lenient.booleanValue());
  }
  return df;
}

代码示例来源:origin: redisson/redisson

private final static DateFormat _cloneFormat(DateFormat df, String format,
    TimeZone tz, Locale loc, Boolean lenient)
{
  if (!loc.equals(DEFAULT_LOCALE)) {
    df = new SimpleDateFormat(format, loc);
    df.setTimeZone((tz == null) ? DEFAULT_TIMEZONE : tz);
  } else {
    df = (DateFormat) df.clone();
    if (tz != null) {
      df.setTimeZone(tz);
    }
  }
  if (lenient != null) {
    df.setLenient(lenient.booleanValue());
  }
  return df;
}

代码示例来源:origin: redisson/redisson

protected DateFormat getDateFormat()
  {
    if (_dateFormat != null) {
      return _dateFormat;
    }
    /* 24-Feb-2012, tatu: At this point, all timezone configuration
     *    should have occurred, with respect to default dateformat
     *    and timezone configuration. But we still better clone
     *    an instance as formatters may be stateful.
     */
    DateFormat df = _config.getDateFormat();
    _dateFormat = df = (DateFormat) df.clone();
    return df;
  }
}

代码示例来源:origin: prestodb/presto

protected DateFormat getDateFormat()
  {
    if (_dateFormat != null) {
      return _dateFormat;
    }
    /* 24-Feb-2012, tatu: At this point, all timezone configuration
     *    should have occurred, with respect to default dateformat
     *    and timezone configuration. But we still better clone
     *    an instance as formatters may be stateful.
     */
    DateFormat df = _config.getDateFormat();
    _dateFormat = df = (DateFormat) df.clone();
    return df;
  }
}

代码示例来源:origin: org.codehaus.jackson/jackson-mapper-asl

protected DateFormat getDateFormat()
{
  if (_dateFormat == null) {
    // must create a clone since Formats are not thread-safe:
    _dateFormat = (DateFormat)_config.getDateFormat().clone();
  }
  return _dateFormat;
}

代码示例来源:origin: prestodb/presto

protected final DateFormat _dateFormat()
  {
    if (_dateFormat != null) {
      return _dateFormat;
    }
    /* At this point, all timezone configuration should have occurred, with respect
     * to default dateformat configuration. But we still better clone
     * an instance as formatters are stateful, not thread-safe.
     */
    DateFormat df = _config.getDateFormat();
    _dateFormat = df = (DateFormat) df.clone();
    // [databind#939]: 26-Sep-2015, tatu: With 2.6, formatter has been (pre)configured
    // with TimeZone, so we should NOT try overriding it unlike with earlier versions
    /*
    TimeZone tz = getTimeZone();
    if (tz != df.getTimeZone()) {
      df.setTimeZone(tz);
    }
    */
    return df;
  }
}

代码示例来源:origin: nutzam/nutz

/**
 * Json输出格式的日期格式
 *
 * @return 日期格式
 */
public DateFormat getDateFormat() {
  DateFormat df = getAs(Function.dateFormat, DateFormat.class);
  return df == null ? null : (DateFormat) df.clone();
}

代码示例来源:origin: redisson/redisson

/**
   * @since 2.9
   */
  protected void _serializeAsString(Date value, JsonGenerator g, SerializerProvider provider) throws IOException
  {
    if (_customFormat == null) {
      provider.defaultSerializeDateValue(value, g);
      return;
    }

    // 19-Jul-2017, tatu: Here we will try a simple but (hopefully) effective mechanism for
    //    reusing formatter instance. This is our second attempt, after initially trying simple
    //    synchronization (which turned out to be bottleneck for some users in production...).
    //    While `ThreadLocal` could alternatively be used, it is likely that it would lead to
    //    higher memory footprint, but without much upside -- if we can not reuse, we'll just
    //    clone(), which has some overhead but not drastic one.
    
    DateFormat f = _reusedCustomFormat.getAndSet(null);
    if (f == null) {
      f = (DateFormat) _customFormat.clone();
    }
    g.writeString(f.format(value));
    _reusedCustomFormat.compareAndSet(null, f);
  }
}

代码示例来源:origin: robovm/robovm

/**
 * Returns a new {@code SimpleDateFormat} with the same pattern and
 * properties as this simple date format.
 */
@Override
public Object clone() {
  SimpleDateFormat clone = (SimpleDateFormat) super.clone();
  clone.formatData = (DateFormatSymbols) formatData.clone();
  clone.defaultCenturyStart = new Date(defaultCenturyStart.getTime());
  return clone;
}

代码示例来源:origin: prestodb/presto

/**
   * @since 2.9
   */
  protected void _serializeAsString(Date value, JsonGenerator g, SerializerProvider provider) throws IOException
  {
    if (_customFormat == null) {
      provider.defaultSerializeDateValue(value, g);
      return;
    }

    // 19-Jul-2017, tatu: Here we will try a simple but (hopefully) effective mechanism for
    //    reusing formatter instance. This is our second attempt, after initially trying simple
    //    synchronization (which turned out to be bottleneck for some users in production...).
    //    While `ThreadLocal` could alternatively be used, it is likely that it would lead to
    //    higher memory footprint, but without much upside -- if we can not reuse, we'll just
    //    clone(), which has some overhead but not drastic one.
    
    DateFormat f = _reusedCustomFormat.getAndSet(null);
    if (f == null) {
      f = (DateFormat) _customFormat.clone();
    }
    g.writeString(f.format(value));
    _reusedCustomFormat.compareAndSet(null, f);
  }
}

相关文章