时间的午夜是由设备的本地语言而不是上午/下午给出的。

huangapple go评论100阅读模式
英文:

time meridiem was given by device local language instead of am/pm

问题

  1. 日期 currentDate = Calendar.getInstance().getTime();
  2. String 时间 = new SimpleDateFormat("HH:mm a").format(currentDate);

现在我得到的时间是上午11:40,而不是上午11:40 am。如何避免在我的应用中使用设备默认语言。

  1. <details>
  2. <summary>英文:</summary>

Date currentDate = Calendar.getInstance().getTime();
String time = new SimpleDateFormat("HH:mm a").format(currentDate);

  1. Now the time i got 11:40 午前 instead of 11:40 am.How to avoid taking device default language in my app.
  2. </details>
  3. # 答案1
  4. **得分**: 0
  5. 使用以 Locale 作为参数的构造函数。
  6. 检查:
  7. https://docs.oracle.com/javase/jp/8/docs/api/java/text/SimpleDateFormat.html#SimpleDateFormat-java.lang.String-java.util.Locale-
  8. 你的代码应该如下所示:
  9. ```java
  10. time = new SimpleDateFormat("HH:mm a", Locale.ENGLISH).format(currentDate);
英文:

Use constructor which takes Locale as its argument.
Check
https://docs.oracle.com/javase/jp/8/docs/api/java/text/SimpleDateFormat.html#SimpleDateFormat-java.lang.String-java.util.Locale-

Your code would go like this:

  1. time = new SimpleDateFormat(&quot;HH:mm a&quot;,Locale.ENGLISH).format(currentDate);

huangapple
  • 本文由 发表于 2020年10月1日 14:25:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/64150108.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定