【问题标题】:DateTime locale string not change even I changed the locale in app in android即使我在 android 中更改了应用程序中的语言环境,DateTime 语言环境字符串也不会改变
【发布时间】:2014-08-21 03:54:21
【问题描述】:

在我的 android 应用中,我已经成功实现了语言更改部分。

问题是,DateTime 语言环境基于设备语言环境而不是应用程序语言环境,例如,当我将应用语言环境从英语切换到德国时,而设备语言环境是英语

字符串/可绘制等是从我的德国字符串文件夹中获得的,但日期仍然是英文的,例如一月、二月等...

这是我获取月份的代码

DateFormatSymbols.getInstance().getShortMonths()[position]

还有,日期的显示方式

String relativeString = getRelativeDateTimeString (this, System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS,DateUtils.WEEK_IN_MILLIS, 0));

如何解决这个问题?谢谢

【问题讨论】:

    标签: android date datetime locale setlocale


    【解决方案1】:

    如何在语言环境中获取日期这个解决方案是

     DateFormat formatter;
     formatter = DateFormat.getTimeInstance(DateFormat.DEFAULT, new Locale("de", "DE"));
     String result = formatter.format(new Date());
    

    从这里你会得到想法并获得帮助,如果你卡住了,请随意问我:)

    我有参考

    1. DateFormat
    2. DateFormat example

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-24
      • 2012-05-15
      相关资源
      最近更新 更多