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

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

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

问题

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

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


<details>
<summary>英文:</summary>

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

 Now the time i got 11:40 午前 instead of 11:40 am.How to avoid taking device default language in my app.

</details>


# 答案1
**得分**: 0

使用以 Locale 作为参数的构造函数。
检查:
https://docs.oracle.com/javase/jp/8/docs/api/java/text/SimpleDateFormat.html#SimpleDateFormat-java.lang.String-java.util.Locale-

你的代码应该如下所示:
```java
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:

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:

确定