Java Code Examples for java.text.DateFormat#LONG

The following examples show how to use java.text.DateFormat#LONG . 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 check out the related API usage on the sidebar.
Example 1
/**
 * Get date-time DateFormat for input based on style.
 * Long date-time format uses short Date and long Time formats
 * Local time zone.
 * 
 * @return a DateFormat based on localizer's locale and time zone
 */  
public DateFormat getInputDateTimeFormat(int style) {
    if (this.dateTimeFormat == null) {
        switch (style) {
            case DateFormat.SHORT: 
                return getInputDateTimeFormat();
            case DateFormat.MEDIUM: 
                return getInputMediumDateTimeFormat();
            case DateFormat.LONG:
                //Uses short date and and long time formats
                return getInputLongDateTimeFormat();
            default:
                return getInputDateTimeFormat();   		              
        }             
    }
    return this.dateTimeFormat;   	
}
 
Example 2
private int getStyle(String style) {
    int ret = DateFormat.DEFAULT;
    if (SHORT.equalsIgnoreCase(style)) {
        ret = DateFormat.SHORT;
    }
    else if (MEDIUM.equalsIgnoreCase(style)) {
        ret = DateFormat.MEDIUM;
    }
    else if (LONG.equalsIgnoreCase(style)) {
        ret = DateFormat.LONG;
    }
    else if (FULL.equalsIgnoreCase(style)) {
        ret = DateFormat.FULL;
    }
    return ret;
}
 
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="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
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 6
Source Project: ph-commons   File: PDTFormatter.java    License: Apache License 2.0 6 votes vote down vote up
@Nonnull
public static FormatStyle toFormatStyle (final int nStyle)
{
  switch (nStyle)
  {
    case DateFormat.FULL:
      return FormatStyle.FULL;
    case DateFormat.LONG:
      return FormatStyle.LONG;
    case DateFormat.MEDIUM:
      return FormatStyle.MEDIUM;
    case DateFormat.SHORT:
      return FormatStyle.SHORT;
    default:
      throw new IllegalArgumentException ("Invalid style passed: " + nStyle);
  }
}
 
Example 7
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 8
public static String getJavaTimePattern(int style, Locale locale) {
   	DateFormat df = DateFormat.getTimeInstance(style, locale);
   	if( df instanceof SimpleDateFormat ) {
   		return ((SimpleDateFormat)df).toPattern();
   	} else {
   		switch( style ) {
   		case DateFormat.SHORT:
   			return "h:mm a";
   		case DateFormat.MEDIUM:
   			return "h:mm:ss a";
   		case DateFormat.LONG:
   			return "h:mm:ss a";
   		case DateFormat.FULL:
   			return "h:mm:ss a";
   		default:
   			return "h:mm:ss a";
   		}
   	}
}
 
Example 9
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 10
/**
 * 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 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
/**
 * Get date only DateFormat for input based on style.
 * Local time zone.
 * 
 * @return a DateFormat based on localizer's locale and time zone
 */  
public DateFormat getInputDateFormat(int style) {
    switch (style) {
        case DateFormat.SHORT: 
            return getInputDateFormat();
        case DateFormat.MEDIUM: 
            return getInputMediumDateFormat();
        case DateFormat.LONG:
            return getInputLongDateFormat();
        default:
            return getInputDateFormat();   		              
    }             
}
 
Example 13
/**
 * 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 14
Source Project: pippo   File: PippoHelper.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 15
Source Project: nebula   File: CDateTime.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Set the date and time format of this CDateTime uses style constants which
 * correspond to the various forms of DateFormat.getXxxInstance(int).
 * <dt><b>Valid Styles:</b></dt>
 * <dd>DATE_SHORT, DATE_MEDIUM, DATE_LONG, TIME_SHORT, TIME_MEDIUM</dd>
 * <p>
 * Styles are bitwise OR'ed together, but only one "DATE" and one "TIME" may
 * be set at a time.
 * </p>
 * Examples:<br>
 * </code>setFormat(CDT.DATE_LONG);</code><br />
 * </code>setFormat(CDT.DATE_SHORT | CDT.TIME_MEDIUM);</code><br />
 * 
 * @param format
 *            the bitwise OR'ed Date and Time format to be set
 * @throws IllegalArgumentException
 * @see #getPattern()
 * @see #setPattern(String)
 */
public void setFormat(int format) throws IllegalArgumentException {
	int dateStyle = (format & CDT.DATE_SHORT) != 0 ? DateFormat.SHORT
			: (format & CDT.DATE_MEDIUM) != 0 ? DateFormat.MEDIUM
					: (format & CDT.DATE_LONG) != 0 ? DateFormat.LONG : -1;
	int timeStyle = (format & CDT.TIME_SHORT) != 0 ? DateFormat.SHORT
			: (format & CDT.TIME_MEDIUM) != 0 ? DateFormat.MEDIUM : -1;
	String str = null;
	if (dateStyle != -1 && timeStyle != -1) {
		str = ((SimpleDateFormat) DateFormat.getDateTimeInstance(dateStyle,
				timeStyle, locale)).toPattern();
	} else if (dateStyle != -1) {
		str = ((SimpleDateFormat) DateFormat.getDateInstance(dateStyle,
				locale)).toPattern();
	} else if (timeStyle != -1) {
		str = ((SimpleDateFormat) DateFormat.getTimeInstance(timeStyle,
				locale)).toPattern();
	} else if (pattern == null) { // first call, so set to default
		format = CDT.DATE_SHORT;
		str = ((SimpleDateFormat) DateFormat
				.getDateInstance(DateFormat.SHORT, locale)).toPattern();
	}
	if (str != null) {
		this.format = format;
		setPattern(str);
	}
}
 
Example 16
@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 17
Source Project: gson   File: PreJava9DateFormatProvider.java    License: 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 18
/**
 * 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 19
/**
 * Creates a new chart title that displays the current date in the default
 * (LONG) format for the locale, positioned to the bottom right of the
 * chart.
 * <P>
 * The color will be black in 12 point, plain Helvetica font (maps to Arial
 * on Win32 systems without Helvetica).
 */
public DateTitle() {
    this(DateFormat.LONG);
}
 
Example 20
Source Project: SIMVA-SoS   File: DateTitle.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new chart title that displays the current date in the default
 * (LONG) format for the locale, positioned to the bottom right of the
 * chart.
 * <P>
 * The color will be black in 12 point, plain Helvetica font (maps to Arial
 * on Win32 systems without Helvetica).
 */
public DateTitle() {
    this(DateFormat.LONG);
}