【问题标题】:Java - Date format with Turkish or other monthsJava - 土耳其语或其他月份的日期格式
【发布时间】:2011-09-27 05:39:22
【问题描述】:

我想用包括土耳其语在内的不同语言的本地化标签来格式化带有月份名称的日期,

如何设置月份的格式化标签

【问题讨论】:

    标签: java date formatting


    【解决方案1】:

    使用SimpleDateFormat constructor 采取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
    

    Locale 接受 ISO-639-1 language code

    【讨论】:

      【解决方案2】:
      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);
          }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-08-16
        • 1970-01-01
        • 1970-01-01
        • 2013-08-07
        • 2014-04-17
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多