@Override public StdDateFormat clone() { // Although there is that much state to share, we do need to // orchestrate a bit, mostly since timezones may be changed return new StdDateFormat(_timezone, _locale, _lenient, _tzSerializedWithColon); }
/** * "Mutant factory" method that will return an instance that has specified * handling of colon when serializing timezone (timezone either written * like {@code +0500} or {@code +05:00}): * either {@code this} instance (if setting would not change), or newly * constructed instance with desired setting for colon inclusion. *<p> * NOTE: does NOT affect deserialization as colon is optional accepted * but not required -- put another way, either serialization is accepted * by this class. * * @since 2.9.1 */ public StdDateFormat withColonInTimeZone(boolean b) { if (_tzSerializedWithColon == b) { return this; } return new StdDateFormat(_timezone, _locale, _lenient, b); }
/** * "Mutant factory" method that will return an instance that uses specified * {@code Locale}: * either {@code this} instance (if setting would not change), or newly * constructed instance with different {@code Locale} to use. */ public StdDateFormat withLocale(Locale loc) { if (loc.equals(_locale)) { return this; } return new StdDateFormat(_timezone, loc, _lenient, _tzSerializedWithColon); }
/** * Method used for creating a new instance with specified timezone; * if no timezone specified, defaults to the default timezone (UTC). */ public StdDateFormat withTimeZone(TimeZone tz) { if (tz == null) { tz = DEFAULT_TIMEZONE; } if ((tz == _timezone) || tz.equals(_timezone)) { return this; } return new StdDateFormat(tz, _locale, _lenient, _tzSerializedWithColon); }
/** * "Mutant factory" method that will return an instance that has specified leniency * setting: either {@code this} instance (if setting would not change), or newly * constructed instance. * * @since 2.9 */ public StdDateFormat withLenient(Boolean b) { if (_equals(b, _lenient)) { return this; } return new StdDateFormat(_timezone, _locale, b, _tzSerializedWithColon); }
private static long parseDateToMillisecs(String valueAsText) { try { return Long.parseLong(valueAsText); } catch (NumberFormatException nfe) { try { return new StdDateFormat().parse(valueAsText).getTime(); } catch (ParseException pe) { throw new IllegalArgumentException("Unable to parse this string as a date: " + valueAsText); } } }
@Override public void initialize(Bootstrap<?> bootstrap) { bootstrap.getObjectMapper().setDateFormat(new StdDateFormat()); bootstrap.getObjectMapper().registerModule(new JtsModule()); bootstrap.getObjectMapper().registerModule(new GraphHopperModule()); bootstrap.getObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL); // Because VirtualEdgeIteratorState has getters which throw Exceptions. // http://stackoverflow.com/questions/35359430/how-to-make-jackson-ignore-properties-if-the-getters-throw-exceptions bootstrap.getObjectMapper().registerModule(new SimpleModule().setSerializerModifier(new BeanSerializerModifier() { @Override public List<BeanPropertyWriter> changeProperties(SerializationConfig config, BeanDescription beanDesc, List<BeanPropertyWriter> beanProperties) { return beanProperties.stream().map(bpw -> new BeanPropertyWriter(bpw) { @Override public void serializeAsField(Object bean, JsonGenerator gen, SerializerProvider prov) throws Exception { try { super.serializeAsField(bean, gen, prov); } catch (Exception e) { // Ignoring expected exception, see above. } } }).collect(Collectors.toList()); } })); }
@Override public Date parse(String source) { try { return super.parse(source);//支持解析指定pattern类型。 } catch (Exception e) { try { return new StdDateFormat().parse(source);//支持解析long类型的时间戳 } catch (ParseException e1) { throw new RuntimeException("日期格式非法:" + e); } } } };
/** * Method used for creating a new instance with specified timezone; * if no timezone specified, defaults to the default timezone (UTC). */ public StdDateFormat withTimeZone(TimeZone tz) { if (tz == null) { tz = DEFAULT_TIMEZONE; } return new StdDateFormat(tz); }
@Override public StdDateFormat clone() { /* Although there is that much state to share, we do need to * orchestrate a bit, mostly since timezones may be changed */ return new StdDateFormat(_timezone, _locale, _lenient); }
@Override public StdDateFormat clone() { // Although there is that much state to share, we do need to // orchestrate a bit, mostly since timezones may be changed return new StdDateFormat(_timezone, _locale, _lenient, _tzSerializedWithColon); }
@Override public StdDateFormat clone() { /* Although there is that much state to share, we do need to * orchestrate a bit, mostly since timezones may be changed */ return new StdDateFormat(); }
@Override public StdDateFormat clone() { /* Although there is that much state to share, we do need to * orchestrate a bit, mostly since timezones may be changed */ return new StdDateFormat(); }
@Override public StdDateFormat clone() { /* Although there is that much state to share, we do need to * orchestrate a bit, mostly since timezones may be changed */ return new StdDateFormat(_timezone, _locale); }
@Override public StdDateFormat clone() { /* Although there is that much state to share, we do need to * orchestrate a bit, mostly since timezones may be changed */ return new StdDateFormat(_timezone, _locale); }
public StdDateFormat withLocale(Locale loc) { if (loc.equals(_locale)) { return this; } return new StdDateFormat(_timezone, loc, _lenient); }
public StdDateFormat withLocale(Locale loc) { if (loc.equals(_locale)) { return this; } return new StdDateFormat(_timezone, loc); }
/** * "Mutant factory" method that will return an instance that uses specified * {@code Locale}: * either {@code this} instance (if setting would not change), or newly * constructed instance with different {@code Locale} to use. */ public StdDateFormat withLocale(Locale loc) { if (loc.equals(_locale)) { return this; } return new StdDateFormat(_timezone, loc, _lenient, _tzSerializedWithColon); }
/** * Method used for creating a new instance with specified timezone; * if no timezone specified, defaults to the default timezone (UTC). */ public StdDateFormat withTimeZone(TimeZone tz) { if (tz == null) { tz = DEFAULT_TIMEZONE; } if (tz.equals(_timezone)) { return this; } return new StdDateFormat(tz, _locale); }
private static long parseDateToMillisecs(String valueAsText) { try { return Long.parseLong(valueAsText); } catch (NumberFormatException nfe) { try { return new StdDateFormat().parse(valueAsText).getTime(); } catch (ParseException pe) { throw new IllegalArgumentException("Unable to parse this string as a date: " + valueAsText); } } }