/** * Converts an object to an instance of {@link Date} using the * specified format and {@link Locale} if the object is not already * an instance of Date, Calendar, or Long. * * @param format - the format the date is in * @param obj - the date to convert * @param locale - the {@link Locale} * @return the object as a {@link Date} or <code>null</code> if no * conversion is possible * @see SimpleDateFormat#parse */ public Date toDate(String format, Object obj, Locale locale) { return toDate(format, obj, locale, getTimeZone()); }
/** * Returns the specified date as a string formatted according to the * specified {@link Locale} and date and/or time styles. * * @param dateStyle the style pattern for the date * @param timeStyle the style pattern for the time * @param obj the date to be formatted * @param locale the {@link Locale} to be used for formatting the date * @param timezone the {@link TimeZone} the date should be formatted for * @return a formatted representation of the given date * @see java.text.DateFormat * @see #format(String dateStyle, String timeStyle, Object obj, Locale locale, TimeZone timezone) * @since VelocityTools 1.1 */ public String format(String dateStyle, String timeStyle, Object obj, Locale locale, TimeZone timezone) { Date date = toDate(obj); DateFormat df = getDateFormat(dateStyle, timeStyle, locale, timezone); if (date == null || df == null) { return null; } return df.format(date); }
Locale locale, TimeZone timezone) Date date = toDate(obj); DateFormat df = getDateFormat(format, locale, timezone); if (date == null || df == null)
/** * Converts an object to an instance of {@link Date} using the * specified format,the {@link Locale} returned by * {@link #getLocale()}, and the {@link TimeZone} returned by * {@link #getTimeZone()} if the object is not already an instance * of Date, Calendar, or Long. * * @param format - the format the date is in * @param obj - the date to convert * @return the object as a {@link Date} or <code>null</code> if no * conversion is possible * @see #toDate(String format, Object obj, Locale locale) */ public Date toDate(String format, Object obj) { return toDate(format, obj, getLocale(), getTimeZone()); }
/** * Converts an object to an instance of {@link Date} using the * format returned by {@link #getFormat()},the {@link Locale} returned * by {@link #getLocale()}, and the {@link TimeZone} returned by * {@link #getTimeZone()} if the object is not already an instance * of Date, Calendar, or Long. * * @param obj the date to convert * @return the object as a {@link Date} or <code>null</code> if no * conversion is possible */ public Date toDate(Object obj) { return toDate(getFormat(), obj, getLocale(), getTimeZone()); }
Date date = toDate(obj); if (date == null)