/** * Register the converters for other types. * </p> * This method registers the following converters: * <ul> * <li><code>Class.class</code> - {@link ClassConverter}</li> * <li><code>java.util.Date.class</code> - {@link DateConverter}</li> * <li><code>java.util.Calendar.class</code> - {@link CalendarConverter}</li> * <li><code>File.class</code> - {@link FileConverter}</li> * <li><code>java.sql.Date.class</code> - {@link SqlDateConverter}</li> * <li><code>java.sql.Time.class</code> - {@link SqlTimeConverter}</li> * <li><code>java.sql.Timestamp.class</code> - {@link SqlTimestampConverter}</li> * <li><code>URL.class</code> - {@link URLConverter}</li> * </ul> * @param throwException <code>true</code> if the converters should * throw an exception when a conversion error occurs, otherwise <code> * <code>false</code> if a default value should be used. */ private void registerOther(final boolean throwException) { register(Class.class, throwException ? new ClassConverter() : new ClassConverter(null)); register(java.util.Date.class, throwException ? new DateConverter() : new DateConverter(null)); register(Calendar.class, throwException ? new CalendarConverter() : new CalendarConverter(null)); register(File.class, throwException ? new FileConverter() : new FileConverter(null)); register(java.sql.Date.class, throwException ? new SqlDateConverter() : new SqlDateConverter(null)); register(java.sql.Time.class, throwException ? new SqlTimeConverter() : new SqlTimeConverter(null)); register(Timestamp.class, throwException ? new SqlTimestampConverter() : new SqlTimestampConverter(null)); register(URL.class, throwException ? new URLConverter() : new URLConverter(null)); }
public TypeConverterUtil(String[] datePatterns) { convertUtilsBean = new ConvertUtilsBean(); final DateConverter dateConverter = new DateConverter(); dateConverter.setPatterns(datePatterns); dateConverter.setTimeZone(TimeZone.getTimeZone("GMT")); convertUtilsBean.register(dateConverter, Date.class); convertUtilsBean.register(new LocalDateTimeConverter(), LocalDateTime.class); convertUtilsBean.register(new LocalDateConverter(), LocalDate.class); convertUtilsBean.register(new OffsetDateTimeConverter(), OffsetDateTime.class); }
/** * 定义日期Converter的格式: yyyy-MM-dd 或 yyyy-MM-dd HH:mm:ss */ private static void registerDateConverter() { DateConverter dc = new DateConverter(); dc.setUseLocaleFormat(true); dc.setPatterns(new String[] { "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss" }); org.apache.commons.beanutils.ConvertUtils.register(dc, Date.class); } }
final DateConverter dateConverter = new DateConverter(); dateConverter.setPatterns(DATE_PATTERNS); dateConverter.setLocale(Locale.FRANCE); dateConverter.setTimeZone(DateUtils.getApplicationTimeZone()); ConvertUtils.register(dateConverter, Date.class);
/** * BeanUtil initialization, considering Lutèce availables locales and date format properties */ public static void init( ) { mapBeanUtilsBeans = new HashMap<>( ); for ( Locale locale : I18nService.getAdminAvailableLocales( ) ) { BeanUtilsBean beanUtilsBean = new BeanUtilsBean( ); beanUtilsBean.getPropertyUtils( ).addBeanIntrospector( SuppressPropertiesBeanIntrospector.SUPPRESS_CLASS ); DateConverter dateConverter = new DateConverter( null ); dateConverter.setPattern( I18nService.getDateFormatShortPattern( locale ) ); beanUtilsBean.getConvertUtils( ).register( dateConverter, Date.class ); mapBeanUtilsBeans.put( locale.getLanguage( ), beanUtilsBean ); } }
public static void setDateTimePattern(String[] patterns) { calendarConverter.setPatterns(patterns); dateConverter.setPatterns(patterns); sqlDateConverter.setPatterns(patterns); sqlTimeConverter.setPatterns(patterns); } }
public EnumAndDateConverter() { dateConverter.setPattern(DATE_PATTERN); }
public TypeConverterUtil(String[] datePatterns) { convertUtilsBean = new ConvertUtilsBean(); final DateConverter dateConverter = new DateConverter(); dateConverter.setPatterns(datePatterns); dateConverter.setTimeZone(TimeZone.getTimeZone("GMT")); convertUtilsBean.register(dateConverter, Date.class); convertUtilsBean.register(new LocalDateTimeConverter(), LocalDateTime.class); convertUtilsBean.register(new LocalDateConverter(), LocalDate.class); convertUtilsBean.register(new OffsetDateTimeConverter(), OffsetDateTime.class); }
/** * 注册一个时间类型的转换器,当前默认的格式为:yyyy-MM-dd * * @param patterns 日期格式 */ public static void registerDateConverter(String... patterns) { DateConverter dc = new DateConverter(); dc.setUseLocaleFormat(true); dc.setPatterns(patterns); register(dc, Date.class); }
/** * Register the converters for other types. * </p> * This method registers the following converters: * <ul> * <li><code>Class.class</code> - {@link ClassConverter}</li> * <li><code>java.util.Date.class</code> - {@link DateConverter}</li> * <li><code>java.util.Calendar.class</code> - {@link CalendarConverter}</li> * <li><code>File.class</code> - {@link FileConverter}</li> * <li><code>java.sql.Date.class</code> - {@link SqlDateConverter}</li> * <li><code>java.sql.Time.class</code> - {@link SqlTimeConverter}</li> * <li><code>java.sql.Timestamp.class</code> - {@link SqlTimestampConverter}</li> * <li><code>URL.class</code> - {@link URLConverter}</li> * </ul> * @param throwException <code>true</code> if the converters should * throw an exception when a conversion error occurs, otherwise <code> * <code>false</code> if a default value should be used. */ private void registerOther(final boolean throwException) { register(Class.class, throwException ? new ClassConverter() : new ClassConverter(null)); register(java.util.Date.class, throwException ? new DateConverter() : new DateConverter(null)); register(Calendar.class, throwException ? new CalendarConverter() : new CalendarConverter(null)); register(File.class, throwException ? new FileConverter() : new FileConverter(null)); register(java.sql.Date.class, throwException ? new SqlDateConverter() : new SqlDateConverter(null)); register(java.sql.Time.class, throwException ? new SqlTimeConverter() : new SqlTimeConverter(null)); register(Timestamp.class, throwException ? new SqlTimestampConverter() : new SqlTimestampConverter(null)); register(URL.class, throwException ? new URLConverter() : new URLConverter(null)); }
registerArrayConverter(java.util.Date.class, new DateConverter(), throwException, defaultArraySize); registerArrayConverter(Calendar.class, new DateConverter(), throwException, defaultArraySize); registerArrayConverter(File.class, new FileConverter(), throwException, defaultArraySize); registerArrayConverter(java.sql.Date.class, new SqlDateConverter(), throwException, defaultArraySize);
registerArrayConverter(java.util.Date.class, new DateConverter(), throwException, defaultArraySize); registerArrayConverter(Calendar.class, new DateConverter(), throwException, defaultArraySize); registerArrayConverter(File.class, new FileConverter(), throwException, defaultArraySize); registerArrayConverter(java.sql.Date.class, new SqlDateConverter(), throwException, defaultArraySize);
ConvertUtils.register( new DateConverter( null ), Date.class ); InputStream input = null;
for (int i = 0; i <= matcher.groupCount()-1; i++) { if (delimitedParserSchema.getFields().get(i).getType() == DelimitedSchema.FieldType.DATE) { DateTimeConverter dtConverter = new DateConverter(); dtConverter.setPattern((String)delimitedParserSchema.getFields().get(i).getConstraints().get(DelimitedSchema.DATE_FORMAT)); ConvertUtils.register(dtConverter, Date.class);
for (int i = 0; i <= matcher.groupCount() - 1; i++) { if (delimitedParserSchema.getFields().get(i).getType() == DelimitedSchema.FieldType.DATE) { DateTimeConverter dtConverter = new DateConverter(); dtConverter.setPattern((String)delimitedParserSchema.getFields().get(i).getConstraints().get(DelimitedSchema.DATE_FORMAT)); ConvertUtils.register(dtConverter, Date.class);
/** * Register the converters for other types. * </p> * This method registers the following converters: * <ul> * <li><code>Class.class</code> - {@link ClassConverter}</li> * <li><code>java.util.Date.class</code> - {@link DateConverter}</li> * <li><code>java.util.Calendar.class</code> - {@link CalendarConverter}</li> * <li><code>File.class</code> - {@link FileConverter}</li> * <li><code>java.sql.Date.class</code> - {@link SqlDateConverter}</li> * <li><code>java.sql.Time.class</code> - {@link SqlTimeConverter}</li> * <li><code>java.sql.Timestamp.class</code> - {@link SqlTimestampConverter}</li> * <li><code>URL.class</code> - {@link URLConverter}</li> * </ul> * @param throwException <code>true</code> if the converters should * throw an exception when a conversion error occurs, otherwise <code> * <code>false</code> if a default value should be used. */ private void registerOther(boolean throwException) { register(Class.class, throwException ? new ClassConverter() : new ClassConverter(null)); register(java.util.Date.class, throwException ? new DateConverter() : new DateConverter(null)); register(Calendar.class, throwException ? new CalendarConverter() : new CalendarConverter(null)); register(File.class, throwException ? new FileConverter() : new FileConverter(null)); register(java.sql.Date.class, throwException ? new SqlDateConverter() : new SqlDateConverter(null)); register(java.sql.Time.class, throwException ? new SqlTimeConverter() : new SqlTimeConverter(null)); register(Timestamp.class, throwException ? new SqlTimestampConverter() : new SqlTimestampConverter(null)); register(URL.class, throwException ? new URLConverter() : new URLConverter(null)); }
/** * Register the converters for other types. * </p> * This method registers the following converters: * <ul> * <li><code>Class.class</code> - {@link ClassConverter}</li> * <li><code>java.util.Date.class</code> - {@link DateConverter}</li> * <li><code>java.util.Calendar.class</code> - {@link CalendarConverter}</li> * <li><code>File.class</code> - {@link FileConverter}</li> * <li><code>java.sql.Date.class</code> - {@link SqlDateConverter}</li> * <li><code>java.sql.Time.class</code> - {@link SqlTimeConverter}</li> * <li><code>java.sql.Timestamp.class</code> - {@link SqlTimestampConverter}</li> * <li><code>URL.class</code> - {@link URLConverter}</li> * </ul> * @param throwException <code>true</code> if the converters should * throw an exception when a conversion error occurs, otherwise <code> * <code>false</code> if a default value should be used. */ private void registerOther(final boolean throwException) { register(Class.class, throwException ? new ClassConverter() : new ClassConverter(null)); register(java.util.Date.class, throwException ? new DateConverter() : new DateConverter(null)); register(Calendar.class, throwException ? new CalendarConverter() : new CalendarConverter(null)); register(File.class, throwException ? new FileConverter() : new FileConverter(null)); register(java.sql.Date.class, throwException ? new SqlDateConverter() : new SqlDateConverter(null)); register(java.sql.Time.class, throwException ? new SqlTimeConverter() : new SqlTimeConverter(null)); register(Timestamp.class, throwException ? new SqlTimestampConverter() : new SqlTimestampConverter(null)); register(URL.class, throwException ? new URLConverter() : new URLConverter(null)); }
/** * Register the converters for other types. * </p> * This method registers the following converters: * <ul> * <li><code>Class.class</code> - {@link ClassConverter}</li> * <li><code>java.util.Date.class</code> - {@link DateConverter}</li> * <li><code>java.util.Calendar.class</code> - {@link CalendarConverter}</li> * <li><code>File.class</code> - {@link FileConverter}</li> * <li><code>java.sql.Date.class</code> - {@link SqlDateConverter}</li> * <li><code>java.sql.Time.class</code> - {@link SqlTimeConverter}</li> * <li><code>java.sql.Timestamp.class</code> - {@link SqlTimestampConverter}</li> * <li><code>URL.class</code> - {@link URLConverter}</li> * </ul> * @param throwException <code>true</code> if the converters should * throw an exception when a conversion error occurs, otherwise <code> * <code>false</code> if a default value should be used. */ private void registerOther(boolean throwException) { register(Class.class, throwException ? new ClassConverter() : new ClassConverter(null)); register(java.util.Date.class, throwException ? new DateConverter() : new DateConverter(null)); register(Calendar.class, throwException ? new CalendarConverter() : new CalendarConverter(null)); register(File.class, throwException ? new FileConverter() : new FileConverter(null)); register(java.sql.Date.class, throwException ? new SqlDateConverter() : new SqlDateConverter(null)); register(java.sql.Time.class, throwException ? new SqlTimeConverter() : new SqlTimeConverter(null)); register(Timestamp.class, throwException ? new SqlTimestampConverter() : new SqlTimestampConverter(null)); register(URL.class, throwException ? new URLConverter() : new URLConverter(null)); }
/** * Register the converters for other types. * </p> * This method registers the following converters: * <ul> * <li><code>Class.class</code> - {@link ClassConverter}</li> * <li><code>java.util.Date.class</code> - {@link DateConverter}</li> * <li><code>java.util.Calendar.class</code> - {@link CalendarConverter}</li> * <li><code>File.class</code> - {@link FileConverter}</li> * <li><code>java.sql.Date.class</code> - {@link SqlDateConverter}</li> * <li><code>java.sql.Time.class</code> - {@link SqlTimeConverter}</li> * <li><code>java.sql.Timestamp.class</code> - {@link SqlTimestampConverter}</li> * <li><code>URL.class</code> - {@link URLConverter}</li> * </ul> * @param throwException <code>true</code> if the converters should * throw an exception when a conversion error occurs, otherwise <code> * <code>false</code> if a default value should be used. */ private void registerOther(boolean throwException) { register(Class.class, throwException ? new ClassConverter() : new ClassConverter(null)); register(java.util.Date.class, throwException ? new DateConverter() : new DateConverter(null)); register(Calendar.class, throwException ? new CalendarConverter() : new CalendarConverter(null)); register(File.class, throwException ? new FileConverter() : new FileConverter(null)); register(java.sql.Date.class, throwException ? new SqlDateConverter() : new SqlDateConverter(null)); register(java.sql.Time.class, throwException ? new SqlTimeConverter() : new SqlTimeConverter(null)); register(Timestamp.class, throwException ? new SqlTimestampConverter() : new SqlTimestampConverter(null)); register(URL.class, throwException ? new URLConverter() : new URLConverter(null)); }
registerArrayConverter(java.util.Date.class, new DateConverter(), throwException, defaultArraySize); registerArrayConverter(Calendar.class, new DateConverter(), throwException, defaultArraySize); registerArrayConverter(File.class, new FileConverter(), throwException, defaultArraySize); registerArrayConverter(java.sql.Date.class, new SqlDateConverter(), throwException, defaultArraySize);