/** * Converts an object to an instance of {@link Calendar} using the * locale returned by {@link #getLocale()} if necessary. * * @param obj the date to convert * @return the converted date * @see #toCalendar(Object obj, Locale locale) */ public Calendar toCalendar(Object obj) { return toCalendar(obj, getLocale()); }
/** * Converts the specified object to a date and returns * a formatted string representing that date in the locale * returned by {@link #getLocale()}. * * @param format the formatting instructions * @param obj the date object to be formatted * @return a formatted string for this locale representing the specified * date or <code>null</code> if the parameters are invalid * @see #format(String format, Object obj, Locale locale, TimeZone timezone) */ public String format(String format, Object obj) { return format(format, obj, getLocale()); }
/** * Returns the specified date as a string formatted according to the * specified 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 * @return a formatted representation of the given date * @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) { return format(dateStyle, timeStyle, obj, getLocale()); }
/** * Returns a {@link Calendar} instance created using the timezone and * locale returned by getTimeZone() and getLocale(). This allows subclasses * to easily override the default locale and timezone used by this tool. * * <p>Sub-classes may override this method to return a Calendar instance * not based on the system date. * Doing so will also cause the getDate(), get(String), get(String,String), * and toString() methods to return dates equivalent to the Calendar * returned by this method, because those methods return values derived * from the result of this method.</p> * * @return a {@link Calendar} instance created using the results of * {@link #getTimeZone()} and {@link #getLocale()}. * @see Calendar#getInstance(TimeZone zone, Locale aLocale) */ public Calendar getCalendar() { return Calendar.getInstance(getTimeZone(), getLocale()); }
/** * Returns a formatted string representing the date and/or time given by * {@link #getDate()} in standard, localized patterns. * * @param dateStyle the style pattern for the date * @param timeStyle the style pattern for the time * @return a formatted representation of the date returned by * {@link #getDate()} * @see DateFormat * @see #format(String dateStyle, String timeStyle, Object obj, Locale locale, TimeZone timezone) * @since VelocityTools 1.1 */ public String get(String dateStyle, String timeStyle) { return format(dateStyle, timeStyle, getDate(), getLocale()); }
/** * 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()); }