Java Code Examples for java.text.DateFormat#MEDIUM

The following examples show how to use java.text.DateFormat#MEDIUM . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
@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 2
@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 3
@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 4
@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
@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
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 7
Source Project: spring-analysis-note   File: DateFormatter.java    License: 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 8
Source Project: pippo   File: FormatTimeMethod.java    License: 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 9
/**
 * 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 10
/**
 * 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 11
@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 Project: j2objc   File: LocaleData.java    License: 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
@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 Project: lams   File: DateFormatter.java    License: 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
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
/**
 * 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
@Override
protected InstantPrinter<DateInstantT> getDefaultInstantPrinter() {
    return new JavaDatePrinter<DateInstantT>(DateFormat.MEDIUM);
}
 
Example 18
/**
 * Constructor.
 */
public DatePicker(Date initialDate) {
	this(initialDate, DateFormat.MEDIUM, Locale.getDefault(), TimeZone
			.getDefault());
}
 
Example 19
/**
 * Constructor.
 */
public DatePicker() {
	this(new Date(), DateFormat.MEDIUM, Locale.getDefault(), TimeZone
			.getDefault());
}
 
Example 20
private void checkDateStyle(int style) {
	if (style != DateFormat.SHORT && style != DateFormat.MEDIUM
			&& style != DateFormat.LONG)
		throw new IllegalArgumentException("dateStyle: unrecognized style");
}