Java Code Examples for java.text.DateFormat#FULL

The following examples show how to use java.text.DateFormat#FULL . 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: DateFormatConverter.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
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";
   		}
   	}
}
 
Example 2
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 3
Source File: PDTFormatter.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
public static int toDateStyle (@Nonnull final FormatStyle eStyle)
{
  switch (eStyle)
  {
    case FULL:
      return DateFormat.FULL;
    case LONG:
      return DateFormat.LONG;
    case MEDIUM:
      return DateFormat.MEDIUM;
    case SHORT:
      return DateFormat.SHORT;
    default:
      throw new IllegalArgumentException ("Unsupported style passed: " + eStyle);
  }
}
 
Example 4
Source File: TCKLocalizedPrinterParser.java    From jdk8u-dev-jdk 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 5
Source File: TCKLocalizedPrinterParser.java    From openjdk-jdk8u-backup 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 6
Source File: TCKLocalizedPrinterParser.java    From jdk8u-jdk 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 7
Source File: DateFormatConverter.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
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";
   		}
   	}
}
 
Example 8
Source File: PippoHelper.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 9
Source File: PippoHelper.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 10
Source File: LocaleData.java    From j2objc with Apache License 2.0 5 votes vote down vote up
public String getTimeFormat(int style) {
    switch (style) {
    case DateFormat.SHORT:
        /* J2ObjC changed - DateFormat.set24HourTimePref is Android-specific API.
        if (DateFormat.is24Hour == null) {
            return shortTimeFormat;
        } else {
            return DateFormat.is24Hour ? timeFormat_Hm : timeFormat_hm;
        }*/
        return shortTimeFormat;
    case DateFormat.MEDIUM:
        /* J2ObjC changed - DateFormat.set24HourTimePref is Android-specific API.
        if (DateFormat.is24Hour == null) {
            return mediumTimeFormat;
        } else {
            return DateFormat.is24Hour ? timeFormat_Hms : timeFormat_hms;
        }*/
        return mediumTimeFormat;
    case DateFormat.LONG:
        // CLDR doesn't really have anything we can use to obey the 12-/24-hour preference.
        return longTimeFormat;
    case DateFormat.FULL:
        // CLDR doesn't really have anything we can use to obey the 12-/24-hour preference.
        return fullTimeFormat;
    }
    throw new AssertionError();
}
 
Example 11
Source File: DateUtil.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
    * Equivalent of <LAMS:Date value="value" type="date|time|both"/>. Use for processing a date to send to the client
    * via JSON. Locale comes from request.getLocale();
    *
    * @param value
    * @param type
    *            TYPE_BOTH (both data and time), TYPE_DATE or TYPE_TIME
    * @param locale
    * @return
    */
   public static String convertToStringForJSON(Date value, Integer style, Integer type, Locale locale) {

HttpSession ss = SessionManager.getSession();
UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER);
TimeZone tz = user.getTimeZone();

int dateStyle, timeStyle;
switch (style) {
    case DateFormat.SHORT:
	dateStyle = DateFormat.SHORT;
	timeStyle = DateFormat.SHORT;
	break;
    case DateFormat.FULL:
	dateStyle = DateFormat.LONG;
	timeStyle = DateFormat.FULL;
	break;
    default:
	dateStyle = DateFormat.LONG;
	timeStyle = DateFormat.MEDIUM;
}

DateFormat df = null;
switch (type) {
    case TYPE_DATE:
	df = DateFormat.getDateInstance(dateStyle, locale);
	break;
    case TYPE_TIME:
	df = DateFormat.getTimeInstance(timeStyle, locale);
	break;
    default:
	df = DateFormat.getDateTimeInstance(dateStyle, timeStyle, locale);
}

if (tz != null) {
    df.setTimeZone(tz);
}

return df.format(value);
   }
 
Example 12
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 13
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 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: PreJava9DateFormatProvider.java    From gson with Apache License 2.0 5 votes vote down vote up
private static String getTimePartOfDateTimePattern(int timeStyle) {
  switch (timeStyle) {
  case DateFormat.SHORT:
    return "h:mm a";
  case DateFormat.MEDIUM:
    return "h:mm:ss a";
  case DateFormat.FULL:
  case DateFormat.LONG:
    return "h:mm:ss a z";
  default:
    throw new IllegalArgumentException("Unknown DateFormat style: " + timeStyle);
  }
}
 
Example 16
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 17
Source File: SakaiDateFormatProvider.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * Returns a time pattern with the given formatting style for the specified
 * locale.
 *
 * @param style the given time formatting style.
 * @param locale the desired locale.
 * @return a time 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 getTimeFormatString(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 = "TimeFormat.SHORT";
		break;
	case DateFormat.MEDIUM:
		key = "TimeFormat.MEDIUM";
		break;
	case DateFormat.LONG:
		key = "TimeFormat.LONG";
		break;
	case DateFormat.FULL:
		key = "TimeFormat.FULL";
		break;
	default:
		throw new IllegalArgumentException("style:" + style);
	}

	return SakaiLocaleServiceProviderUtil.getString(key, locale);
}
 
Example 18
Source File: LocaleDateFormats.java    From TencentKona-8 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 19
Source File: PreJava9DateFormatProvider.java    From gson with Apache License 2.0 5 votes vote down vote up
private static String getDateFormatPattern(int style) {
  switch (style) {
  case DateFormat.SHORT:
    return "M/d/yy";
  case DateFormat.MEDIUM:
    return "MMM d, y";
  case DateFormat.LONG:
    return "MMMM d, y";
  case DateFormat.FULL:
    return "EEEE, MMMM d, y";
  default:
    throw new IllegalArgumentException("Unknown DateFormat style: " + style);
  }
}
 
Example 20
Source File: DateTimeFunctions.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * This methods tries to convert a generic object into a java.util.Date instance.
 * Supported types are for now String, Long values (time millis) and Date subtypes
 * like for example java.sql.Date.
 */
private Date convertDateObject(Object dateObject){
	if(dateObject==null){
		if(log.isDebugEnabled()){
			log.debug("The date object can not be null.");
		}
		return null;
	}
	else if(dateObject instanceof String){
		// Try to convert using the different style for pattern.
		// We use MEDIUM as the first one because it is the DEFAULT
		int formatTypes[] = new int[]{DateFormat.MEDIUM, DateFormat.SHORT, DateFormat.LONG, DateFormat.FULL};
		for(int formatType : formatTypes) {
			try {
				DateFormat df = DateFormat.getDateInstance(formatType, getReportLocale());
				df.setTimeZone(getReportTimeZone());
				return df.parse((String)dateObject);
			} catch (ParseException e) {
				if(log.isDebugEnabled()){
					log.debug("Unable to parse the string as Date using the standard SimpleDateFormat.");
				}
			}
		}
		return null;
	}
	else if(dateObject instanceof Long){
		Calendar cal = Calendar.getInstance(getReportTimeZone(), getReportLocale());
		cal.setTimeInMillis((Long)dateObject);
		return cal.getTime();
	}
	else if(dateObject instanceof Date){
		return (Date)dateObject;
	}
	if(log.isDebugEnabled()){
		log.debug("The specified object is not among the allowed types for Date conversion.");
	}
	return null;
}