例如,您可以这样做(例如如何从法语语言环境转换为立欢语):
@Test
public void testTestLocale() throws Exception {
Date date = new Date();
// Get a France locale
Locale localeFR = Locale.FRANCE;
// Create a Lithuanian Locale
Locale localeLT = new Locale("lt", "LT");
// Get a date time formatter for display in France
DateFormat fullDateFormatFR =DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL,localeFR);
// Get a date time formatter for display in Lithuania
DateFormat fullDateFormatLT = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, localeLT);
System.out.println("Locale: "+localeFR.getDisplayName());
System.out.println(fullDateFormatFR.format(date));
System.out.println("Locale: "+localeLT.getDisplayName());
System.out.println(fullDateFormatLT.format(date));
}
编辑:从完成到美国格式的工作样本转换日期:
@Test
public void testConvertDateFromFinToEn() throws Exception {
String dateInFin = "helmikuu 13, 2013";
Locale localeFi = new Locale("fi", "FI");
DateFormat dateFormatFi = new SimpleDateFormat("MMMM dd, yyyy", localeFi);
// Get Date object
Date date = dateFormatFi.parse(dateInFin);
// Convert to US date format
Locale localeUS = new Locale("en", "US");
DateFormat dateFormatUS = new SimpleDateFormat("dd MMMM, yyyy", localeUS);
// Print in US format
System.out.println(dateFormatUS.format(date));
}