@Override public TimeZone getTimeZone() { TimeZone timeZone = RequestContextUtils.getTimeZone(this.request); return (timeZone != null ? timeZone : super.getTimeZone()); } }
@Override public TimeZone getTimeZone() { TimeZone timeZone = RequestContextUtils.getTimeZone(this.request); return (timeZone != null ? timeZone : super.getTimeZone()); } }
@Override public TimeZone getTimeZone() { TimeZone timeZone = RequestContextUtils.getTimeZone(this.request); return (timeZone != null ? timeZone : super.getTimeZone()); } }
/** * Converts the specified object to a date and returns * a formatted string representing that date in the specified * {@link Locale}. * * @param format the formatting instructions * @param obj the date object to be formatted * @param locale the locale to be used when formatting * @return the given date as a formatted string * @see #format(String format, Object obj, Locale locale, TimeZone timezone) */ public String format(String format, Object obj, Locale locale) { return format(format, obj, locale, getTimeZone()); }
/** * 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 * @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, Locale locale) { return format(dateStyle, timeStyle, obj, locale, getTimeZone()); }
/** * 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()); }
/** * 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()); }
/** * Returns a localized date format pattern for the given format. * * SimpleDateFormat uses patterns that are based upon English * words (such as Month = M, Day = d, and Year = y). When displaying * a format pattern to readers of other languages, it is appropriate * to display these patterns using their localized expectations. * For instance, the date pattern yyyy-MM-dd should, for French speakers * appear as "aaaa-MM-jj". {@link SimpleDateFormat#toLocalizedPattern} * provides this functionality, and this method merely calls * that on an appropriately-constructed SimpleDateFormat object. * * @param format the custom or standard pattern to convert * @param locale the {@link Locale} to format for pattern for * @return a format string appropriate for the specified Locale * @since VelocityTools 2.0 */ public String toLocalizedPattern(String format, Locale locale) { DateFormat df = getDateFormat(format, locale, getTimeZone()); // Just in case DateFormat.getInstance doesn't return SimpleDateFormat if(df instanceof SimpleDateFormat) return ((SimpleDateFormat)df).toLocalizedPattern(); else return null; // Got a better idea? }
/** * 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()); }