Java Code Examples for java.text.DateFormat#DEFAULT
The following examples show how to use
java.text.DateFormat#DEFAULT .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FormatDateTag.java From uyuni with GNU General Public License v2.0 | 6 votes |
private int getStyle(String style) { int ret = DateFormat.DEFAULT; if (SHORT.equalsIgnoreCase(style)) { ret = DateFormat.SHORT; } else if (MEDIUM.equalsIgnoreCase(style)) { ret = DateFormat.MEDIUM; } else if (LONG.equalsIgnoreCase(style)) { ret = DateFormat.LONG; } else if (FULL.equalsIgnoreCase(style)) { ret = DateFormat.FULL; } return ret; }
Example 2
Source File: GsonBuilder.java From GVGAI_GYM with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") private void addTypeAdaptersForDate(String datePattern, int dateStyle, int timeStyle, List<TypeAdapterFactory> factories) { DefaultDateTypeAdapter dateTypeAdapter; TypeAdapter<Timestamp> timestampTypeAdapter; TypeAdapter<java.sql.Date> javaSqlDateTypeAdapter; if (datePattern != null && !"".equals(datePattern.trim())) { dateTypeAdapter = new DefaultDateTypeAdapter(Date.class, datePattern); timestampTypeAdapter = (TypeAdapter) new DefaultDateTypeAdapter(Timestamp.class, datePattern); javaSqlDateTypeAdapter = (TypeAdapter) new DefaultDateTypeAdapter(java.sql.Date.class, datePattern); } else if (dateStyle != DateFormat.DEFAULT && timeStyle != DateFormat.DEFAULT) { dateTypeAdapter = new DefaultDateTypeAdapter(Date.class, dateStyle, timeStyle); timestampTypeAdapter = (TypeAdapter) new DefaultDateTypeAdapter(Timestamp.class, dateStyle, timeStyle); javaSqlDateTypeAdapter = (TypeAdapter) new DefaultDateTypeAdapter(java.sql.Date.class, dateStyle, timeStyle); } else { return; } factories.add(TypeAdapters.newFactory(Date.class, dateTypeAdapter)); factories.add(TypeAdapters.newFactory(Timestamp.class, timestampTypeAdapter)); factories.add(TypeAdapters.newFactory(java.sql.Date.class, javaSqlDateTypeAdapter)); }
Example 3
Source File: GsonBuilder.java From GVGAI_GYM with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") private void addTypeAdaptersForDate(String datePattern, int dateStyle, int timeStyle, List<TypeAdapterFactory> factories) { DefaultDateTypeAdapter dateTypeAdapter; TypeAdapter<Timestamp> timestampTypeAdapter; TypeAdapter<java.sql.Date> javaSqlDateTypeAdapter; if (datePattern != null && !"".equals(datePattern.trim())) { dateTypeAdapter = new DefaultDateTypeAdapter(Date.class, datePattern); timestampTypeAdapter = (TypeAdapter) new DefaultDateTypeAdapter(Timestamp.class, datePattern); javaSqlDateTypeAdapter = (TypeAdapter) new DefaultDateTypeAdapter(java.sql.Date.class, datePattern); } else if (dateStyle != DateFormat.DEFAULT && timeStyle != DateFormat.DEFAULT) { dateTypeAdapter = new DefaultDateTypeAdapter(Date.class, dateStyle, timeStyle); timestampTypeAdapter = (TypeAdapter) new DefaultDateTypeAdapter(Timestamp.class, dateStyle, timeStyle); javaSqlDateTypeAdapter = (TypeAdapter) new DefaultDateTypeAdapter(java.sql.Date.class, dateStyle, timeStyle); } else { return; } factories.add(TypeAdapters.newFactory(Date.class, dateTypeAdapter)); factories.add(TypeAdapters.newFactory(Timestamp.class, timestampTypeAdapter)); factories.add(TypeAdapters.newFactory(java.sql.Date.class, javaSqlDateTypeAdapter)); }
Example 4
Source File: GsonBuilder.java From gson with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") private void addTypeAdaptersForDate(String datePattern, int dateStyle, int timeStyle, List<TypeAdapterFactory> factories) { DefaultDateTypeAdapter dateTypeAdapter; TypeAdapter<Timestamp> timestampTypeAdapter; TypeAdapter<java.sql.Date> javaSqlDateTypeAdapter; if (datePattern != null && !"".equals(datePattern.trim())) { dateTypeAdapter = new DefaultDateTypeAdapter(Date.class, datePattern); timestampTypeAdapter = (TypeAdapter) new DefaultDateTypeAdapter(Timestamp.class, datePattern); javaSqlDateTypeAdapter = (TypeAdapter) new DefaultDateTypeAdapter(java.sql.Date.class, datePattern); } else if (dateStyle != DateFormat.DEFAULT && timeStyle != DateFormat.DEFAULT) { dateTypeAdapter = new DefaultDateTypeAdapter(Date.class, dateStyle, timeStyle); timestampTypeAdapter = (TypeAdapter) new DefaultDateTypeAdapter(Timestamp.class, dateStyle, timeStyle); javaSqlDateTypeAdapter = (TypeAdapter) new DefaultDateTypeAdapter(java.sql.Date.class, dateStyle, timeStyle); } else { return; } factories.add(TypeAdapters.newFactory(Date.class, dateTypeAdapter)); factories.add(TypeAdapters.newFactory(Timestamp.class, timestampTypeAdapter)); factories.add(TypeAdapters.newFactory(java.sql.Date.class, javaSqlDateTypeAdapter)); }
Example 5
Source File: FormatDateTag.java From spacewalk with GNU General Public License v2.0 | 6 votes |
private int getStyle(String style) { int ret = DateFormat.DEFAULT; if (SHORT.equalsIgnoreCase(style)) { ret = DateFormat.SHORT; } else if (MEDIUM.equalsIgnoreCase(style)) { ret = DateFormat.MEDIUM; } else if (LONG.equalsIgnoreCase(style)) { ret = DateFormat.LONG; } else if (FULL.equalsIgnoreCase(style)) { ret = DateFormat.FULL; } return ret; }
Example 6
Source File: DateTimeKit.java From jfinal-ext3 with Apache License 2.0 | 5 votes |
/** * 格式化时间 * @param style * @param date * @see DateFormat * @return */ public static String formatDate(int style,Date date){ if (date == null) { return ""; } if (style < 0) { style = DateFormat.DEFAULT; } return DateFormat.getDateInstance(style).format(date); }
Example 7
Source File: DefaultFormatFactory.java From jasperreports with GNU Lesser General Public License v3.0 | 5 votes |
protected static int[] getDateStyle(String pattern) { if (pattern.equalsIgnoreCase(STANDARD_DATE_FORMAT_DEFAULT)) { return new int[]{DateFormat.DEFAULT}; } else if (pattern.equalsIgnoreCase(STANDARD_DATE_FORMAT_SHORT)) { return new int[]{DateFormat.SHORT}; } else if (pattern.equalsIgnoreCase(STANDARD_DATE_FORMAT_MEDIUM)) { return new int[]{DateFormat.MEDIUM}; } else if (pattern.equalsIgnoreCase(STANDARD_DATE_FORMAT_LONG)) { return new int[]{DateFormat.LONG}; } else if (pattern.equalsIgnoreCase(STANDARD_DATE_FORMAT_FULL)) { return new int[]{DateFormat.FULL}; } else if (pattern.equalsIgnoreCase(STANDARD_DATE_FORMAT_HIDE)) { return new int[0]; } else { return null; } }
Example 8
Source File: GsonBuilder.java From sagetv with Apache License 2.0 | 5 votes |
private void addTypeAdaptersForDate(String datePattern, int dateStyle, int timeStyle, List<TypeAdapterFactory> factories) { DefaultDateTypeAdapter dateTypeAdapter; if (datePattern != null && !"".equals(datePattern.trim())) { dateTypeAdapter = new DefaultDateTypeAdapter(datePattern); } else if (dateStyle != DateFormat.DEFAULT && timeStyle != DateFormat.DEFAULT) { dateTypeAdapter = new DefaultDateTypeAdapter(dateStyle, timeStyle); } else { return; } factories.add(TreeTypeAdapter.newFactory(TypeToken.get(Date.class), dateTypeAdapter)); factories.add(TreeTypeAdapter.newFactory(TypeToken.get(Timestamp.class), dateTypeAdapter)); factories.add(TreeTypeAdapter.newFactory(TypeToken.get(java.sql.Date.class), dateTypeAdapter)); }
Example 9
Source File: GsonTest.java From gson with Apache License 2.0 | 5 votes |
public void testOverridesDefaultExcluder() { Gson gson = new Gson(CUSTOM_EXCLUDER, CUSTOM_FIELD_NAMING_STRATEGY, new HashMap<Type, InstanceCreator<?>>(), true, false, true, false, true, true, false, LongSerializationPolicy.DEFAULT, null, DateFormat.DEFAULT, DateFormat.DEFAULT, new ArrayList<TypeAdapterFactory>(), new ArrayList<TypeAdapterFactory>(), new ArrayList<TypeAdapterFactory>()); assertEquals(CUSTOM_EXCLUDER, gson.excluder()); assertEquals(CUSTOM_FIELD_NAMING_STRATEGY, gson.fieldNamingStrategy()); assertEquals(true, gson.serializeNulls()); assertEquals(false, gson.htmlSafe()); }
Example 10
Source File: GsonTest.java From gson with Apache License 2.0 | 5 votes |
public void testClonedTypeAdapterFactoryListsAreIndependent() { Gson original = new Gson(CUSTOM_EXCLUDER, CUSTOM_FIELD_NAMING_STRATEGY, new HashMap<Type, InstanceCreator<?>>(), true, false, true, false, true, true, false, LongSerializationPolicy.DEFAULT, null, DateFormat.DEFAULT, DateFormat.DEFAULT, new ArrayList<TypeAdapterFactory>(), new ArrayList<TypeAdapterFactory>(), new ArrayList<TypeAdapterFactory>()); Gson clone = original.newBuilder() .registerTypeAdapter(Object.class, new TestTypeAdapter()) .create(); assertEquals(original.factories.size() + 1, clone.factories.size()); }
Example 11
Source File: GsonBuilder.java From framework with GNU Affero General Public License v3.0 | 5 votes |
private void addTypeAdaptersForDate(String datePattern, int dateStyle, int timeStyle, List<TypeAdapterFactory> factories) { DefaultDateTypeAdapter dateTypeAdapter; if (datePattern != null && !"".equals(datePattern.trim())) { dateTypeAdapter = new DefaultDateTypeAdapter(datePattern); } else if (dateStyle != DateFormat.DEFAULT && timeStyle != DateFormat.DEFAULT) { dateTypeAdapter = new DefaultDateTypeAdapter(dateStyle, timeStyle); } else { return; } factories.add(TreeTypeAdapter.newFactory(TypeToken.get(Date.class), dateTypeAdapter)); factories.add(TreeTypeAdapter.newFactory(TypeToken.get(Timestamp.class), dateTypeAdapter)); factories.add(TreeTypeAdapter.newFactory(TypeToken.get(java.sql.Date.class), dateTypeAdapter)); }
Example 12
Source File: Gson.java From gson with Apache License 2.0 | 3 votes |
/** * Constructs a Gson object with default configuration. The default configuration has the * following settings: * <ul> * <li>The JSON generated by <code>toJson</code> methods is in compact representation. This * means that all the unneeded white-space is removed. You can change this behavior with * {@link GsonBuilder#setPrettyPrinting()}. </li> * <li>The generated JSON omits all the fields that are null. Note that nulls in arrays are * kept as is since an array is an ordered list. Moreover, if a field is not null, but its * generated JSON is empty, the field is kept. You can configure Gson to serialize null values * by setting {@link GsonBuilder#serializeNulls()}.</li> * <li>Gson provides default serialization and deserialization for Enums, {@link Map}, * {@link java.net.URL}, {@link java.net.URI}, {@link java.util.Locale}, {@link java.util.Date}, * {@link java.math.BigDecimal}, and {@link java.math.BigInteger} classes. If you would prefer * to change the default representation, you can do so by registering a type adapter through * {@link GsonBuilder#registerTypeAdapter(Type, Object)}. </li> * <li>The default Date format is same as {@link java.text.DateFormat#DEFAULT}. This format * ignores the millisecond portion of the date during serialization. You can change * this by invoking {@link GsonBuilder#setDateFormat(int)} or * {@link GsonBuilder#setDateFormat(String)}. </li> * <li>By default, Gson ignores the {@link com.google.gson.annotations.Expose} annotation. * You can enable Gson to serialize/deserialize only those fields marked with this annotation * through {@link GsonBuilder#excludeFieldsWithoutExposeAnnotation()}. </li> * <li>By default, Gson ignores the {@link com.google.gson.annotations.Since} annotation. You * can enable Gson to use this annotation through {@link GsonBuilder#setVersion(double)}.</li> * <li>The default field naming policy for the output Json is same as in Java. So, a Java class * field <code>versionNumber</code> will be output as <code>"versionNumber"</code> in * Json. The same rules are applied for mapping incoming Json to the Java classes. You can * change this policy through {@link GsonBuilder#setFieldNamingPolicy(FieldNamingPolicy)}.</li> * <li>By default, Gson excludes <code>transient</code> or <code>static</code> fields from * consideration for serialization and deserialization. You can change this behavior through * {@link GsonBuilder#excludeFieldsWithModifiers(int...)}.</li> * </ul> */ public Gson() { this(Excluder.DEFAULT, FieldNamingPolicy.IDENTITY, Collections.<Type, InstanceCreator<?>>emptyMap(), DEFAULT_SERIALIZE_NULLS, DEFAULT_COMPLEX_MAP_KEYS, DEFAULT_JSON_NON_EXECUTABLE, DEFAULT_ESCAPE_HTML, DEFAULT_PRETTY_PRINT, DEFAULT_LENIENT, DEFAULT_SPECIALIZE_FLOAT_VALUES, LongSerializationPolicy.DEFAULT, null, DateFormat.DEFAULT, DateFormat.DEFAULT, Collections.<TypeAdapterFactory>emptyList(), Collections.<TypeAdapterFactory>emptyList(), Collections.<TypeAdapterFactory>emptyList()); }