Monday, August 18, 2008

Java Date

/** Format: May 16, 2008 */
public static String formatDefaultUSA(Date date)
{
String countryCode = "US";
String languageCode = "en";
return convertToLocalized(date, countryCode, languageCode, DateFormat.DEFAULT);
}
public static String convertToLocalized(Date date, String countryCode, String languageCode, int format)
{
Locale locale = new Locale(languageCode, countryCode);
DateFormat df = DateFormat.getDateInstance(format, locale);
return df.format(date);
}

/** Format: 5/14/08 */
public static String formatShortUsa(Date date)
{
String countryCode = "US";
String languageCode = "en";
int format = DateFormat.SHORT;
return convertToLocalized(date, countryCode, languageCode, format);
}