List of usage examples for com.google.gwt.i18n.client DateTimeFormatInfo dateFormatShort
String dateFormatShort();
From source file:com.smartgwt.client.util.DateUtil.java
License:Open Source License
/** * Use the GWT LocaleInfo class to auto-detect the various formats for dates and times. * *//*from w w w.java 2s .c o m*/ public static void autoDetectFormats() { // rather than using the default US locale, use the GWT defaults for the current locale com.google.gwt.i18n.client.DateTimeFormatInfo i = com.google.gwt.i18n.client.LocaleInfo.getCurrentLocale() .getDateTimeFormatInfo(); final String shortDate = i.dateFormatShort(); final String shortDateTime = shortDate + " " + i.timeFormatShort(); final String normalDate = shortDate; final com.google.gwt.i18n.client.DateTimeFormat shortDateFormat = com.google.gwt.i18n.client.DateTimeFormat .getFormat(shortDate); final com.google.gwt.i18n.client.DateTimeFormat shortDateTimeFormat = com.google.gwt.i18n.client.DateTimeFormat .getFormat(shortDateTime); final com.google.gwt.i18n.client.DateTimeFormat normalDateFormat = shortDateFormat; DateUtil.setShortDateDisplayFormatter(new DateDisplayFormatter() { @Override public String format(Date date) { if (date == null) return null; return shortDateFormat.format(date); } }); DateUtil.setShortDatetimeDisplayFormatter(new DateDisplayFormatter() { @Override public String format(Date date) { if (date == null) return null; return shortDateTimeFormat.format(date); } }); DateUtil.setNormalDateDisplayFormatter(new DateDisplayFormatter() { @Override public String format(Date date) { if (date == null) return null; return normalDateFormat.format(date); } }); // try to guess DMY, MDY or YMD from shortDate ... StringBuilder dmy = new StringBuilder(); for (char c : shortDate.toCharArray()) { switch (c) { case 'd': if (dmy.indexOf("D") == -1) dmy.append("D"); break; case 'M': if (dmy.indexOf("M") == -1) dmy.append("M"); break; case 'y': if (dmy.indexOf("Y") == -1) dmy.append("Y"); break; } if (dmy.length() == 3) { DateUtil.setDateInputFormat(dmy.toString()); break; } } }
From source file:org.ssgwt.client.i18n.DateTimeFormat.java
License:Apache License
/** * Get a DateTimeFormat instance for a predefined format. * * <p>See {@link CustomDateTimeFormat} if you need a localized format that is * not supported here./*from ww w . j av a 2 s.co m*/ * * @param predef {@link PredefinedFormat} describing desired format * @return a DateTimeFormat instance for the specified format */ public static DateTimeFormat getFormat(PredefinedFormat predef) { if (usesFixedEnglishStrings(predef)) { String pattern; switch (predef) { case RFC_2822: pattern = org.ssgwt.share.i18n.DateTimeFormat.RFC2822_PATTERN; break; case ISO_8601: pattern = org.ssgwt.share.i18n.DateTimeFormat.ISO8601_PATTERN; break; default: throw new IllegalStateException("Unexpected predef type " + predef); } return getFormat(pattern, new DateTimeFormatInfoImpl_en()); } DateTimeFormatInfo dtfi = getDefaultDateTimeFormatInfo(); String pattern; switch (predef) { case DATE_FULL: pattern = dtfi.dateFormatFull(); break; case DATE_LONG: pattern = dtfi.dateFormatLong(); break; case DATE_MEDIUM: pattern = dtfi.dateFormatMedium(); break; case DATE_SHORT: pattern = dtfi.dateFormatShort(); break; case DATE_TIME_FULL: pattern = dtfi.dateTimeFull(dtfi.timeFormatFull(), dtfi.dateFormatFull()); break; case DATE_TIME_LONG: pattern = dtfi.dateTimeLong(dtfi.timeFormatLong(), dtfi.dateFormatLong()); break; case DATE_TIME_MEDIUM: pattern = dtfi.dateTimeMedium(dtfi.timeFormatMedium(), dtfi.dateFormatMedium()); break; case DATE_TIME_SHORT: pattern = dtfi.dateTimeShort(dtfi.timeFormatShort(), dtfi.dateFormatShort()); break; case DAY: pattern = dtfi.formatDay(); break; case HOUR24_MINUTE: pattern = dtfi.formatHour24Minute(); break; case HOUR24_MINUTE_SECOND: pattern = dtfi.formatHour24MinuteSecond(); break; case HOUR_MINUTE: pattern = dtfi.formatHour12Minute(); break; case HOUR_MINUTE_SECOND: pattern = dtfi.formatHour12MinuteSecond(); break; case MINUTE_SECOND: pattern = dtfi.formatMinuteSecond(); break; case MONTH: pattern = dtfi.formatMonthFull(); break; case MONTH_ABBR: pattern = dtfi.formatMonthAbbrev(); break; case MONTH_ABBR_DAY: pattern = dtfi.formatMonthAbbrevDay(); break; case MONTH_DAY: pattern = dtfi.formatMonthFullDay(); break; case MONTH_NUM_DAY: pattern = dtfi.formatMonthNumDay(); break; case MONTH_WEEKDAY_DAY: pattern = dtfi.formatMonthFullWeekdayDay(); break; case TIME_FULL: pattern = dtfi.timeFormatFull(); break; case TIME_LONG: pattern = dtfi.timeFormatLong(); break; case TIME_MEDIUM: pattern = dtfi.timeFormatMedium(); break; case TIME_SHORT: pattern = dtfi.timeFormatShort(); break; case YEAR: pattern = dtfi.formatYear(); break; case YEAR_MONTH: pattern = dtfi.formatYearMonthFull(); break; case YEAR_MONTH_ABBR: pattern = dtfi.formatYearMonthAbbrev(); break; case YEAR_MONTH_ABBR_DAY: pattern = dtfi.formatYearMonthAbbrevDay(); break; case YEAR_MONTH_DAY: pattern = dtfi.formatYearMonthFullDay(); break; case YEAR_MONTH_NUM: pattern = dtfi.formatYearMonthNum(); break; case YEAR_MONTH_NUM_DAY: pattern = dtfi.formatYearMonthNumDay(); break; case YEAR_MONTH_WEEKDAY_DAY: pattern = dtfi.formatYearMonthWeekdayDay(); break; case YEAR_QUARTER: pattern = dtfi.formatYearQuarterFull(); break; case YEAR_QUARTER_ABBR: pattern = dtfi.formatYearQuarterShort(); break; default: throw new IllegalArgumentException("Unexpected predefined format " + predef); } return getFormat(pattern, dtfi); }