开发者

Java - Date format with Turkish or other months

开发者 https://www.devze.com 2023-04-09 04:11 出处:网络
I want to format 开发者_StackOverflow社区dates with month names with localized label in different languages including Turkish,

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);
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号