Blankj / Blankj/AndroidUtilCode

TimeUtils切换语言时会有bug

Open
#1,786 0 comments 1 reaction 1 assignee Claimed by @Blankj View on GitHub
bug
Dominant language
Java
Stars
33.6k
Forks
10.6k
PR merge metrics
No merged PRs in 30d

Description

## 描述 Bug
1.在中文环境下,使用TimeUtils.millis2String(long millis, @NonNull final String pattern)方法,pattern传入:h:mm a,获取到的时间能正常显示,如:8:00上午
2.切换系统语言为其他语言,此时重复上面的步骤,获取到的时间显示不对,在其他语言环境下,仍显示:8:00上午,显示错误

- AndroidUtilCode 的版本:utilscodex:1.31.1
- 出现 Bug 的设备型号:华为畅享50
- 设备的 Android 版本:Android 10

查看源码,TimeUtils类里的SDF_THREAD_LOCAL里面已经缓存了SimpleDateFormat,切换语言时,因为h:mm a使用过,缓存在SDF_THREAD_LOCAL,不会重新添加,但此时的simpleDateFormat是在中文环境创建的,导致出来的时间一直是中文,切换了语言也不会变……

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.