Java Code Examples for java.text.DateFormat#MEDIUM

The following examples show how to use java.text.DateFormat#MEDIUM . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TCKLocalizedPrinterParser.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
@DataProvider(name="date")
Object[][] data_date() {
    return new Object[][] {
            {LocalDate.of(2012, 6, 30), FormatStyle.SHORT, DateFormat.SHORT, Locale.UK},
            {LocalDate.of(2012, 6, 30), FormatStyle.SHORT, DateFormat.SHORT, Locale.US},
            {LocalDate.of(2012, 6, 30), FormatStyle.SHORT, DateFormat.SHORT, Locale.FRANCE},
            {LocalDate.of(2012, 6, 30), FormatStyle.SHORT, DateFormat.SHORT, Locale.JAPAN},

            {LocalDate.of(2012, 6, 30), FormatStyle.MEDIUM, DateFormat.MEDIUM, Locale.UK},
            {LocalDate.of(2012, 6, 30), FormatStyle.MEDIUM, DateFormat.MEDIUM, Locale.US},
            {LocalDate.of(2012, 6, 30), FormatStyle.MEDIUM, DateFormat.MEDIUM, Locale.FRANCE},
            {LocalDate.of(2012, 6, 30), FormatStyle.MEDIUM, DateFormat.MEDIUM, Locale.JAPAN},

            {LocalDate.of(2012, 6, 30), FormatStyle.LONG, DateFormat.LONG, Locale.UK},
            {LocalDate.of(2012, 6, 30), FormatStyle.LONG, DateFormat.LONG, Locale.US},
            {LocalDate.of(2012, 6, 30), FormatStyle.LONG, DateFormat.LONG, Locale.FRANCE},
            {LocalDate.of(2012, 6, 30), FormatStyle.LONG, DateFormat.LONG, Locale.JAPAN},

            {LocalDate.of(2012, 6, 30), FormatStyle.FULL, DateFormat.FULL, Locale.UK},
            {LocalDate.of(2012, 6, 30), FormatStyle.FULL, DateFormat.FULL, Locale.US},
            {LocalDate.of(2012, 6, 30), FormatStyle.FULL, DateFormat.FULL, Locale.FRANCE},
            {LocalDate.of(2012, 6, 30), FormatStyle.FULL, DateFormat.FULL, Locale.JAPAN},
    };
}
 
Example 2
Source File: DateFormatConverter.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public static String getJavaDateTimePattern(int style, Locale locale) {
   	DateFormat df = DateFormat.getDateTimeInstance(style, style, locale);
   	if( df instanceof SimpleDateFormat ) {
   		return ((SimpleDateFormat)df).toPattern();
   	} else {
   		switch( style ) {
   		case DateFormat.SHORT:
   			return "M/d/yy h:mm a";
   		case DateFormat.MEDIUM:
   			return "MMM d, yyyy h:mm:ss a";
   		case DateFormat.LONG:
   			return "MMMM d, yyyy h:mm:ss a";
   		case DateFormat.FULL:
   			return "dddd, MMMM d, yyyy h:mm:ss a";
   		default:
   			return "MMM d, yyyy h:mm:ss a";
   		}
   	}
}
 
Example 3
Source File: TCKLocalizedPrinterParser.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@DataProvider(name="time")
    Object[][] data_time() {
        return new Object[][] {
                {LocalTime.of(11, 30), FormatStyle.SHORT, DateFormat.SHORT, Locale.UK},
                {LocalTime.of(11, 30), FormatStyle.SHORT, DateFormat.SHORT, Locale.US},
                {LocalTime.of(11, 30), FormatStyle.SHORT, DateFormat.SHORT, Locale.FRANCE},
                {LocalTime.of(11, 30), FormatStyle.SHORT, DateFormat.SHORT, Locale.JAPAN},

                {LocalTime.of(11, 30), FormatStyle.MEDIUM, DateFormat.MEDIUM, Locale.UK},
                {LocalTime.of(11, 30), FormatStyle.MEDIUM, DateFormat.MEDIUM, Locale.US},
                {LocalTime.of(11, 30), FormatStyle.MEDIUM, DateFormat.MEDIUM, Locale.FRANCE},
                {LocalTime.of(11, 30), FormatStyle.MEDIUM, DateFormat.MEDIUM, Locale.JAPAN},

                // these localized patterns include "z" which isn't available from LocalTime
//                {LocalTime.of(11, 30), FormatStyle.LONG, DateFormat.LONG, Locale.UK},
//                {LocalTime.of(11, 30), FormatStyle.LONG, DateFormat.LONG, Locale.US},
//                {LocalTime.of(11, 30), FormatStyle.LONG, DateFormat.LONG, Locale.FRANCE},
//                {LocalTime.of(11, 30), FormatStyle.LONG, DateFormat.LONG, Locale.JAPAN},
//
//                {LocalTime.of(11, 30), FormatStyle.FULL, DateFormat.FULL, Locale.UK},
//                {LocalTime.of(11, 30), FormatStyle.FULL, DateFormat.FULL, Locale.US},
//                {LocalTime.of(11, 30), FormatStyle.FULL, DateFormat.FULL, Locale.FRANCE},
//                {LocalTime.of(11, 30), FormatStyle.FULL, DateFormat.FULL, Locale.JAPAN},
        };
    }
 
Example 4
Source File: TCKLocalizedPrinterParser.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
@DataProvider(name="time")
    Object[][] data_time() {
        return new Object[][] {
                {LocalTime.of(11, 30), FormatStyle.SHORT, DateFormat.SHORT, Locale.UK},
                {LocalTime.of(11, 30), FormatStyle.SHORT, DateFormat.SHORT, Locale.US},
                {LocalTime.of(11, 30), FormatStyle.SHORT, DateFormat.SHORT, Locale.FRANCE},
                {LocalTime.of(11, 30), FormatStyle.SHORT, DateFormat.SHORT, Locale.JAPAN},

                {LocalTime.of(11, 30), FormatStyle.MEDIUM, DateFormat.MEDIUM, Locale.UK},
                {LocalTime.of(11, 30), FormatStyle.MEDIUM, DateFormat.MEDIUM, Locale.US},
                {LocalTime.of(11, 30), FormatStyle.MEDIUM, DateFormat.MEDIUM, Locale.FRANCE},
                {LocalTime.of(11, 30), FormatStyle.MEDIUM, DateFormat.MEDIUM, Locale.JAPAN},

                // these localized patterns include "z" which isn't available from LocalTime
//                {LocalTime.of(11, 30), FormatStyle.LONG, DateFormat.LONG, Locale.UK},
//                {LocalTime.of(11, 30), FormatStyle.LONG, DateFormat.LONG, Locale.US},
//                {LocalTime.of(11, 30), FormatStyle.LONG, DateFormat.LONG, Locale.FRANCE},
//                {LocalTime.of(11, 30), FormatStyle.LONG, DateFormat.LONG, Locale.JAPAN},
//
//                {LocalTime.of(11, 30), FormatStyle.FULL, DateFormat.FULL, Locale.UK},
//                {LocalTime.of(11, 30), FormatStyle.FULL, DateFormat.FULL, Locale.US},
//                {LocalTime.of(11, 30), FormatStyle.FULL, DateFormat.FULL, Locale.FRANCE},
//                {LocalTime.of(11, 30), FormatStyle.FULL, DateFormat.FULL, Locale.JAPAN},
        };
    }
 
Example 5
Source File: TCKLocalizedPrinterParser.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
@DataProvider(name="time")
    Object[][] data_time() {
        return new Object[][] {
                {LocalTime.of(11, 30), FormatStyle.SHORT, DateFormat.SHORT, Locale.UK},
                {LocalTime.of(11, 30), FormatStyle.SHORT, DateFormat.SHORT, Locale.US},
                {LocalTime.of(11, 30), FormatStyle.SHORT, DateFormat.SHORT, Locale.FRANCE},
                {LocalTime.of(11, 30), FormatStyle.SHORT, DateFormat.SHORT, Locale.JAPAN},

                {LocalTime.of(11, 30), FormatStyle.MEDIUM, DateFormat.MEDIUM, Locale.UK},
                {LocalTime.of(11, 30), FormatStyle.MEDIUM, DateFormat.MEDIUM, Locale.US},
                {LocalTime.of(11, 30), FormatStyle.MEDIUM, DateFormat.MEDIUM, Locale.FRANCE},
                {LocalTime.of(11, 30), FormatStyle.MEDIUM, DateFormat.MEDIUM, Locale.JAPAN},

                // these localized patterns include "z" which isn't available from LocalTime
//                {LocalTime.of(11, 30), FormatStyle.LONG, DateFormat.LONG, Locale.UK},
//                {LocalTime.of(11, 30), FormatStyle.LONG, DateFormat.LONG, Locale.US},
//                {LocalTime.of(11, 30), FormatStyle.LONG, DateFormat.LONG, Locale.FRANCE},
//                {LocalTime.of(11, 30), FormatStyle.LONG, DateFormat.LONG, Locale.JAPAN},
//
//                {LocalTime.of(11, 30), FormatStyle.FULL, DateFormat.FULL, Locale.UK},
//                {LocalTime.of(11, 30), FormatStyle.FULL, DateFormat.FULL, Locale.US},
//                {LocalTime.of(11, 30), FormatStyle.FULL, DateFormat.FULL, Locale.FRANCE},
//                {LocalTime.of(11, 30), FormatStyle.FULL, DateFormat.FULL, Locale.JAPAN},
        };
    }
 
Example 6
Source File: TCKLocalizedPrinterParser.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
@DataProvider(name="time")
    Object[][] data_time() {
        return new Object[][] {
                {LocalTime.of(11, 30), FormatStyle.SHORT, DateFormat.SHORT, Locale.UK},
                {LocalTime.of(11, 30), FormatStyle.SHORT, DateFormat.SHORT, Locale.US},
                {LocalTime.of(11, 30), FormatStyle.SHORT, DateFormat.SHORT, Locale.FRANCE},
                {LocalTime.of(11, 30), FormatStyle.SHORT, DateFormat.SHORT, Locale.JAPAN},

                {LocalTime.of(11, 30), FormatStyle.MEDIUM, DateFormat.MEDIUM, Locale.UK},
                {LocalTime.of(11, 30), FormatStyle.MEDIUM, DateFormat.MEDIUM, Locale.US},
                {LocalTime.of(11, 30), FormatStyle.MEDIUM, DateFormat.MEDIUM, Locale.FRANCE},
                {LocalTime.of(11, 30), FormatStyle.MEDIUM, DateFormat.MEDIUM, Locale.JAPAN},

                // these localized patterns include "z" which isn't available from LocalTime
//                {LocalTime.of(11, 30), FormatStyle.LONG, DateFormat.LONG, Locale.UK},
//                {LocalTime.of(11, 30), FormatStyle.LONG, DateFormat.LONG, Locale.US},
//                {LocalTime.of(11, 30), FormatStyle.LONG, DateFormat.LONG, Locale.FRANCE},
//                {LocalTime.of(11, 30), FormatStyle.LONG, DateFormat.LONG, Locale.JAPAN},
//
//                {LocalTime.of(11, 30), FormatStyle.FULL, DateFormat.FULL, Locale.UK},
//                {LocalTime.of(11, 30), FormatStyle.FULL, DateFormat.FULL, Locale.US},
//                {LocalTime.of(11, 30), FormatStyle.FULL, DateFormat.FULL, Locale.FRANCE},
//                {LocalTime.of(11, 30), FormatStyle.FULL, DateFormat.FULL, Locale.JAPAN},
        };
    }
 
Example 7
Source File: FormatTimeMethod.java    From pippo with Apache License 2.0 5 votes vote down vote up
protected Integer parseStyle(String style) {
    if ("full".equals(style)) {
        return DateFormat.FULL;
    } else if ("long".equals(style)) {
        return DateFormat.LONG;
    } else if ("short".equals(style)) {
        return DateFormat.SHORT;
    } else if ("medium".equals(style)) {
        return DateFormat.MEDIUM;
    } else {
        return -1;
    }
}
 
Example 8
Source File: SakaiDateFormatProvider.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * Returns a date pattern with the given formatting style for the specified
 * locale.
 *
 * @param style the given date formatting style.
 * @param locale the desired locale.
 * @return a date pattern.
 * @throws IllegalArgumentException if <code>style</code> is invalid, or if
 *     <code>locale</code> isn't available.
 * @throws NullPointerException if <code>locale</code> is <code>null</code>.
 */
protected String getDateFormatString(final int style, final Locale locale) throws IllegalArgumentException,
		NullPointerException {
	if (locale == null) {
		throw new NullPointerException("locale:null");
	} else if (!SakaiLocaleServiceProviderUtil.isAvailableLocale(locale)) {
		throw new IllegalArgumentException("locale:" + locale.toString());
	}

	String key;
	switch (style) {
	case DateFormat.SHORT:
		key = "DateFormat.SHORT";
		break;
	case DateFormat.MEDIUM:
		key = "DateFormat.MEDIUM";
		break;
	case DateFormat.LONG:
		key = "DateFormat.LONG";
		break;
	case DateFormat.FULL:
		key = "DateFormat.FULL";
		break;
	default:
		throw new IllegalArgumentException("style:" + style);
	}

	return SakaiLocaleServiceProviderUtil.getString(key, locale);
}
 
Example 9
Source File: BaseLocalizer.java    From grammaticus with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Get date-only DateFormat for output based on style. 4-digit year 
 *
 * @param style
 * @return a DateFormat based on localizer's locale and time zone
 */   
public DateFormat getDateFormat(int style) {
    switch (style) {
        case DateFormat.SHORT: 
            return getDateFormat();
        case DateFormat.MEDIUM: 
            return getMediumDateFormat();
        case DateFormat.LONG:
            return getLongDateFormat();
        default:
            return getDateFormat();   		                          
    }	
}
 
Example 10
Source File: DateFormatter.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private int getStylePatternForChar(int index) {
	if (this.stylePattern != null && this.stylePattern.length() > index) {
		switch (this.stylePattern.charAt(index)) {
			case 'S': return DateFormat.SHORT;
			case 'M': return DateFormat.MEDIUM;
			case 'L': return DateFormat.LONG;
			case 'F': return DateFormat.FULL;
			case '-': return -1;
		}
	}
	throw new IllegalStateException("Unsupported style pattern '" + this.stylePattern + "'");
}
 
Example 11
Source File: LocaleDateFormats.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name = "dateFormats" )
private Object[][] dateFormats() {
    return new Object[][] {
        //8080774
        //Locale, Format type, year, month, date, expected result
        {localeEnSG, DateFormat.SHORT, 2015, 5, 6, "6/5/15"},
        {localeEnSG, DateFormat.MEDIUM, 2015, 5, 6, "6 May, 2015"},
        {localeEnSG, DateFormat.LONG, 2015, 5, 6, "6 May, 2015"},
        {localeEnSG, DateFormat.FULL, 2015, 5, 6, "Wednesday, 6 May, 2015"}
    };
}
 
Example 12
Source File: LocaleData.java    From j2objc with Apache License 2.0 5 votes vote down vote up
public String getDateFormat(int style) {
    switch (style) {
    case DateFormat.SHORT:
        return shortDateFormat;
    case DateFormat.MEDIUM:
        return mediumDateFormat;
    case DateFormat.LONG:
        return longDateFormat;
    case DateFormat.FULL:
        return fullDateFormat;
    }
    throw new AssertionError();
}
 
Example 13
Source File: LocaleDateFormats.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name = "dateFormats" )
private Object[][] dateFormats() {
    return new Object[][] {
        //8080774
        //Locale, Format type, year, month, date, expected result
        {localeEnSG, DateFormat.SHORT, 2015, 5, 6, "6/5/15"},
        {localeEnSG, DateFormat.MEDIUM, 2015, 5, 6, "6 May, 2015"},
        {localeEnSG, DateFormat.LONG, 2015, 5, 6, "6 May, 2015"},
        {localeEnSG, DateFormat.FULL, 2015, 5, 6, "Wednesday, 6 May, 2015"}
    };
}
 
Example 14
Source File: DateFormatter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private int getStylePatternForChar(int index) {
	if (this.stylePattern != null && this.stylePattern.length() > index) {
		switch (this.stylePattern.charAt(index)) {
			case 'S': return DateFormat.SHORT;
			case 'M': return DateFormat.MEDIUM;
			case 'L': return DateFormat.LONG;
			case 'F': return DateFormat.FULL;
			case '-': return -1;
		}
	}
	throw new IllegalStateException("Unsupported style pattern '" + this.stylePattern + "'");
}
 
Example 15
Source File: DumpPatterns.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static String typeToString(int type)
{
  switch (type)
  {
    case DateFormat.SHORT: return "short";
    case DateFormat.MEDIUM: return "medium";
    case DateFormat.LONG: return "long";
    case DateFormat.FULL: return "full";
    default:
      throw new NullPointerException();
  }
}
 
Example 16
Source File: BaseLocalizer.java    From grammaticus with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Static method to get DateFormat for time input based on style
 * Caller must do doParseTime for parsing
 * @param locale locale
 * @param style DateFormat style
 * @param tz time zone
 * @return a date-only DateFormat.
 */
public static DateFormat getLocaleInputTimeFormat(Locale locale, int style, TimeZone tz) {   	    
    DateFormat df ;   
    
    switch (style) {
        case DateFormat.SHORT :
            df = getFormatProvider(locale).getTimeInstance(DateFormat.SHORT, locale);
            break;
        case DateFormat.MEDIUM :
            df = getFormatProvider(locale).getTimeInstance(DateFormat.MEDIUM, locale);
            break;
        case DateFormat.LONG :
            df = getFormatProvider(locale).getTimeInstance(DateFormat.LONG, locale);
            break;
        default :
            df = getFormatProvider(locale).getTimeInstance(DateFormat.SHORT, locale);
    }
    
    df.setLenient(false);
    df.setTimeZone(tz);
    Calendar calendar = df.getCalendar();
    calendar.set(Calendar.YEAR, 1959);  // 60 means 1960, 59 means 2059; handle potential daylight saving difference
    calendar.set(Calendar.MONTH, calendar.getActualMaximum(Calendar.MONTH));
    calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
    calendar.set(Calendar.HOUR_OF_DAY, calendar.getActualMaximum(Calendar.HOUR_OF_DAY));
    calendar.set(Calendar.MINUTE, calendar.getActualMinimum(Calendar.MINUTE));
    ((SimpleDateFormat)df).set2DigitYearStart(calendar.getTime());
    return df;
}
 
Example 17
Source File: DatePicker.java    From microba with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Constructor.
 */
public DatePicker(Date initialDate) {
	this(initialDate, DateFormat.MEDIUM, Locale.getDefault(), TimeZone
			.getDefault());
}
 
Example 18
Source File: DatePicker.java    From microba with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Constructor.
 */
public DatePicker() {
	this(new Date(), DateFormat.MEDIUM, Locale.getDefault(), TimeZone
			.getDefault());
}
 
Example 19
Source File: DatePicker.java    From microba with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void checkDateStyle(int style) {
	if (style != DateFormat.SHORT && style != DateFormat.MEDIUM
			&& style != DateFormat.LONG)
		throw new IllegalArgumentException("dateStyle: unrecognized style");
}
 
Example 20
Source File: FloatingLabelDatePicker.java    From android-floatinglabel-widgets with Apache License 2.0 4 votes vote down vote up
@Override
protected InstantPrinter<DateInstantT> getDefaultInstantPrinter() {
    return new JavaDatePrinter<DateInstantT>(DateFormat.MEDIUM);
}