【问题标题】:Custom datetime formats for various locales in AndroidAndroid 中各种语言环境的自定义日期时间格式
【发布时间】:2017-11-07 20:37:05
【问题描述】:

我正在寻找有关如何在我的 Android 应用程序中为各种语言环境(例如芬兰语、法语等)设置日期和时间格式的文档。我在 Android 的文档中找不到此信息。

【问题讨论】:

    标签: android localization


    【解决方案1】:
    // (1) get today's date
    Date today = Calendar.getInstance().getTime();
    
    // (2) create our date "formatter" (the date format we want)
    SimpleDateFormat formatter = new SimpleDateFormat("EEE MMM dd hh:mm:ss yyyy");
    
    // (3) create a new String using the date format we want
    String result = formatter.format(today);
    
    // (4) this prints "Result = Sun Sep 06 08:32:51 2009" in English and will be translated depending on phone Locale
    System.out.println("Result = " + result);
    

    来源:http://alvinalexander.com/java/simpledateformat-convert-date-to-string-formatted-parse

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-23
      • 1970-01-01
      • 2010-11-23
      • 1970-01-01
      相关资源
      最近更新 更多