Skip to content

TimeUtils切换语言时会有bug #1786

Open
@keyingming

Description

@keyingming

描述 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是在中文环境创建的,导致出来的时间一直是中文,切换了语言也不会变……

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions