android pm.java,java – AM / PM的Android DateFormat因设备而异
发布日期:2021-06-24 14:52:29 浏览次数:3 分类:技术文章

本文共 739 字,大约阅读时间需要 2 分钟。

我正在格式化这样的日期:

public static String toFormattedDate(@NonNull Time time, String toFormat) {

mDateFormat = new SimpleDateFormat(toFormat);

Date date = new Date();

date.setTime(time.toMillis(true));

return mDateFormat.format(date);

}

我使用的格式是:

public static final String TIME = "hh:mm a";

但它在我用于测试的两个设备之间有所不同……

Nexus 10:

ggrTO.png

Nexus 5X:

pfqZs.png

如何在设备之间统一格式化?

解决方法:

您可能必须使用24小时值来确定要追加的内容,以便您可以添加所需的格式.

public static final String TIME = "hh:mm";

然后

String ampm = Integer.parseInt(time.valueOf("hh")) >= 12 ? "PM" : "AM";

...

return mDateFormat.format(date)+" "+ampm;

或者,如果你感到懒惰,你可以不改变TIME的值:

return mDateFormat.format(date).toUpperCase().replace(".","");

标签:java,android,date-format,simpledateformat,android-date

来源: https://codeday.me/bug/20190623/1269007.html

转载地址:https://blog.csdn.net/weixin_33458486/article/details/116262675 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:oracle存储过程调用sql文件,oracle - 在SQL Developer中运行存储过程?
下一篇:php 常用文件系统函数,php 文件系统函数整理介绍

发表评论

最新留言

路过,博主的博客真漂亮。。
[***.116.15.85]2024年04月14日 08时05分59秒