I want to format 开发者_StackOverflow社区dates with month names with localized label in different languages including Turkish,
how do I set formatted labels for months
Use the SimpleDateFormat
constructor taking a Locale
.
SimpleDateFormat sdf = new SimpleDateFormat("dd MMMM yyyy", new Locale("tr"));
String date = sdf.format(new Date());
System.out.println(date); // 27 Eylül 2011
The Locale
accepts an ISO-639-1 language code.
public static void main(String Args[]) {
String text = "Çar, 11 Eyl 2013 19:28:14 +03:00";
try {
Date sdf = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss", new Locale("tr")).parse(text);
SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String date = DATE_FORMAT.format(sdf);
System.out.println(date);
} catch (ParseException ex) {
Logger.getLogger(test.class.getName()).log(Level.SEVERE, null, ex);
}
}
精彩评论