Refine search
String getPattern(Locale locale) { DateFormat f = null; switch (iType) { case DATE: f = DateFormat.getDateInstance(iDateStyle, locale); break; case TIME: f = DateFormat.getTimeInstance(iTimeStyle, locale); break; case DATETIME: f = DateFormat.getDateTimeInstance(iDateStyle, iTimeStyle, locale); break; } if (f instanceof SimpleDateFormat == false) { throw new IllegalArgumentException("No datetime pattern for locale: " + locale); } return ((SimpleDateFormat) f).toPattern(); } }
Locale locale = Locale.getDefault(); SimpleDateFormat sdf = (SimpleDateFormat)DateFormat.getDateInstance(DateFormat.SHORT, locale ); String format = sdf.toPattern();
String getPattern(Locale locale) { DateFormat f = null; switch (iType) { case DATE: f = DateFormat.getDateInstance(iDateStyle, locale); break; case TIME: f = DateFormat.getTimeInstance(iTimeStyle, locale); break; case DATETIME: f = DateFormat.getDateTimeInstance(iDateStyle, iTimeStyle, locale); break; } if (f instanceof SimpleDateFormat == false) { throw new IllegalArgumentException("No datetime pattern for locale: " + locale); } return ((SimpleDateFormat) f).toPattern(); } }
public static String getJavaDatePattern(int style, Locale locale) { DateFormat df = DateFormat.getDateInstance(style, locale); if( df instanceof SimpleDateFormat ) { return ((SimpleDateFormat)df).toPattern(); } else { switch( style ) { case DateFormat.SHORT: return "d/MM/yy"; case DateFormat.MEDIUM: return "MMM d, yyyy"; case DateFormat.LONG: return "MMMM d, yyyy"; case DateFormat.FULL: return "dddd, MMMM d, yyyy"; default: return "MMM d, yyyy"; } } }
String getPattern(Locale locale) { DateFormat f = null; switch (iType) { case DATE: f = DateFormat.getDateInstance(iDateStyle, locale); break; case TIME: f = DateFormat.getTimeInstance(iTimeStyle, locale); break; case DATETIME: f = DateFormat.getDateTimeInstance(iDateStyle, iTimeStyle, locale); break; } if (f instanceof SimpleDateFormat == false) { throw new IllegalArgumentException("No datetime pattern for locale: " + locale); } return ((SimpleDateFormat) f).toPattern(); } }
public static void main(String[] args) throws Exception { for (Locale locale : Locale.getAvailableLocales()) { DateFormat df = getShortDateInstanceWithoutYears(locale); System.out.println(locale + ": " + df.format(new Date())); } } public static DateFormat getShortDateInstanceWithoutYears(Locale locale) { SimpleDateFormat sdf = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.SHORT, locale); sdf.applyPattern(sdf.toPattern().replaceAll("[^\\p{Alpha}]*y+[^\\p{Alpha}]*", "")); return sdf; }
DateFormat formatter = DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault()); String pattern = ((SimpleDateFormat)formatter).toPattern(); String localPattern = ((SimpleDateFormat)formatter).toLocalizedPattern();
formatter = DateFormat.getTimeInstance(timeStyle.intValue(), locale); } else if (timeStyle == null) { formatter = DateFormat.getDateInstance(dateStyle.intValue(), locale); } else { formatter = DateFormat.getDateTimeInstance(dateStyle.intValue(), timeStyle.intValue(), locale); pattern = ((SimpleDateFormat)formatter).toPattern(); final String previous = cDateTimeInstanceCache.putIfAbsent(key, pattern); if (previous != null) {
static String getPatternForStyle(final Integer dateStyle, final Integer timeStyle, final Locale locale) { final MultipartKey key = new MultipartKey(dateStyle, timeStyle, locale); String pattern = cDateTimeInstanceCache.get(key); if (pattern == null) { try { DateFormat formatter; if (dateStyle == null) { formatter = DateFormat.getTimeInstance(timeStyle, locale); } else if (timeStyle == null) { formatter = DateFormat.getDateInstance(dateStyle, locale); } else { formatter = DateFormat.getDateTimeInstance(dateStyle, timeStyle, locale); } pattern = ((SimpleDateFormat) formatter).toPattern(); final String previous = cDateTimeInstanceCache.putIfAbsent(key, pattern); if (previous != null) { // even though it doesn't matter if another thread put the pattern // it's still good practice to return the String instance that is // actually in the ConcurrentMap pattern = previous; } } catch (final ClassCastException ex) { throw new IllegalArgumentException("No date time pattern for locale: " + locale); } } return pattern; }
static String getPatternForStyle(final Integer dateStyle, final Integer timeStyle, final Locale locale) { final MultipartKey key = new MultipartKey(dateStyle, timeStyle, locale); String pattern = cDateTimeInstanceCache.get(key); if (pattern == null) { try { DateFormat formatter; if (dateStyle == null) { formatter = DateFormat.getTimeInstance(timeStyle, locale); } else if (timeStyle == null) { formatter = DateFormat.getDateInstance(dateStyle, locale); } else { formatter = DateFormat.getDateTimeInstance(dateStyle, timeStyle, locale); } pattern = ((SimpleDateFormat) formatter).toPattern(); final String previous = cDateTimeInstanceCache.putIfAbsent(key, pattern); if (previous != null) { // even though it doesn't matter if another thread put the pattern // it's still good practice to return the String instance that is // actually in the ConcurrentMap pattern = previous; } } catch (final ClassCastException ex) { throw new IllegalArgumentException("No date time pattern for locale: " + locale); } } return pattern; }
private String decodeSimpleDateFormat(StringBuffer buffer, Format format) { if (format.equals(DateFormat.getTimeInstance(DateFormat.DEFAULT, locale))) { buffer.append(",time"); } else if (format.equals(DateFormat.getDateInstance(DateFormat.DEFAULT, locale))) { buffer.append(",date"); } else if (format.equals(DateFormat.getTimeInstance(DateFormat.SHORT, locale))) { buffer.append(",time,short"); } else if (format.equals(DateFormat.getDateInstance(DateFormat.SHORT, locale))) { buffer.append(",date,short"); } else if (format.equals(DateFormat.getTimeInstance(DateFormat.LONG, locale))) { buffer.append(",time,long"); } else if (format.equals(DateFormat.getDateInstance(DateFormat.LONG, locale))) { buffer.append(",date,long"); } else if (format.equals(DateFormat.getTimeInstance(DateFormat.FULL, locale))) { buffer.append(",time,full"); } else if (format.equals(DateFormat.getDateInstance(DateFormat.FULL, locale))) { buffer.append(",date,full"); } else { buffer.append(",date,"); return ((SimpleDateFormat) format).toPattern(); } return null; }
if (format == null) { try { SimpleDateFormat formatter = (SimpleDateFormat) DateFormat.getDateInstance(style, locale); String pattern = formatter.toPattern(); format = getInstance(pattern, timeZone, locale); cDateInstanceCache.put(key, format);
formatter = DateFormat.getTimeInstance(timeStyle.intValue(), locale); } else if (timeStyle == null) { formatter = DateFormat.getDateInstance(dateStyle.intValue(), locale); } else { formatter = DateFormat.getDateTimeInstance(dateStyle.intValue(), timeStyle.intValue(), locale); pattern = ((SimpleDateFormat) formatter).toPattern(); final String previous = cDateTimeInstanceCache.putIfAbsent(key, pattern); if (previous != null) {
formatter = DateFormat.getTimeInstance(timeStyle.intValue(), locale); } else if (timeStyle == null) { formatter = DateFormat.getDateInstance(dateStyle.intValue(), locale); } else { formatter = DateFormat.getDateTimeInstance(dateStyle.intValue(), timeStyle.intValue(), locale); pattern = ((SimpleDateFormat) formatter).toPattern(); final String previous = cDateTimeInstanceCache.putIfAbsent(key, pattern); if (previous != null) {
public String calculateTimeOnlyPattern() { if (timeOnlyPattern == null) { String localePattern = ((SimpleDateFormat) DateFormat.getDateInstance(DateFormat.SHORT, calculateLocale(getFacesContext()))).toPattern(); String userTimePattern = getPattern(); timeOnlyPattern = localePattern + " " + userTimePattern; } return timeOnlyPattern; }
public String calculatePattern() { String pattern = getPattern(); Locale locale = calculateLocale(getFacesContext()); return pattern == null ? ((SimpleDateFormat) DateFormat.getDateInstance(DateFormat.SHORT, locale)).toPattern() : pattern; }
String pattern = ((SimpleDateFormat)DateFormat.getDateInstance(ds, locale)).toPattern(); format = getInstance(pattern, timeZone, locale); cDateInstanceCache.put(key, format);
DateFormat df = null; if (type.equals("both")) { df = DateFormat.getDateInstance(getStyle(dateStyle), this.getLocale()); metadata.put(HTML.VALIDATION_METADATA.DATE_STYLE_PATTERN, CalendarUtils.convertPattern(((SimpleDateFormat) df).toPattern())); df = DateFormat.getTimeInstance(getStyle(timeStyle), this.getLocale()); metadata.put(HTML.VALIDATION_METADATA.TIME_STYLE_PATTERN, CalendarUtils.convertPattern(((SimpleDateFormat) df).toPattern())); df = DateFormat.getDateInstance(getStyle(dateStyle), this.getLocale()); metadata.put(HTML.VALIDATION_METADATA.DATE_STYLE_PATTERN, CalendarUtils.convertPattern(((SimpleDateFormat) df).toPattern())); metadata.put(HTML.VALIDATION_METADATA.TIME_STYLE_PATTERN, CalendarUtils.convertPattern(((SimpleDateFormat) df).toPattern()));
String getPattern(Locale locale) { DateFormat f = null; switch (iType) { case DATE: f = DateFormat.getDateInstance(iDateStyle, locale); break; case TIME: f = DateFormat.getTimeInstance(iTimeStyle, locale); break; case DATETIME: f = DateFormat.getDateTimeInstance(iDateStyle, iTimeStyle, locale); break; } if (f instanceof SimpleDateFormat == false) { throw new IllegalArgumentException("No datetime pattern for locale: " + locale); } return ((SimpleDateFormat) f).toPattern(); } }
SimpleDateFormat sdf = (SimpleDateFormat) SimpleDateFormat.getDateInstance(DateFormat.SHORT, l); String pattern = sdf.toPattern(); String localizedPattern = sdf.toLocalizedPattern() println "country: " + l.getDisplayName();