protected Date parseAsRFC1123(String dateStr, ParsePosition pos) { if (_formatRFC1123 == null) { _formatRFC1123 = (DateFormat) DATE_FORMAT_RFC1123.clone(); } return _formatRFC1123.parse(dateStr, pos); }
/** * 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; }
@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); }
/** * 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; }
/** * 以给定的时间格式来安全的解析时间字符串,并返回解析后所对应的时间对象 * * @param fmt * 时间格式 * @param s * 日期时间字符串 * @return 该时间字符串对应的时间对象 */ public static Date parse(DateFormat fmt, String s) throws ParseException { return ((DateFormat) fmt.clone()).parse(s); }
/** * 以给定的时间格式来安全的对时间进行格式化,并返回格式化后所对应的字符串 * * @param fmt * 时间格式 * @param d * 时间对象 * @return 格式化后的字符串 */ public static String format(DateFormat fmt, Date d) { return ((DateFormat) fmt.clone()).format(d); }
/** * @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); }
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); }
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; } }
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; } }
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; }
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; }
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; } }
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; } }
protected DateFormat getDateFormat() { if (_dateFormat == null) { // must create a clone since Formats are not thread-safe: _dateFormat = (DateFormat)_config.getDateFormat().clone(); } return _dateFormat; }
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; } }
/** * Json输出格式的日期格式 * * @return 日期格式 */ public DateFormat getDateFormat() { DateFormat df = getAs(Function.dateFormat, DateFormat.class); return df == null ? null : (DateFormat) df.clone(); }
/** * @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); } }
/** * 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; }
/** * @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); } }