简体   繁体   English

检测android系统日期/时间格式更改并反映在应用程序中

[英]Detect android system date/time format change and reflect in the app

I want the app to correspond to the system time format change. 我希望该应用程序与系统时间格式更改相对应。 For Instance, if i change android system time format to 24hr format. 对于实例,如果我将android系统时间格式更改为24hr格式。 I want my app to detect that change and reflect the change in the app. 我希望我的应用程序能够检测到该更改并在应用程序中反映该更改。 Hence if the system time format is 24hrs then the time displayed inside the app should be in 24hrs as well and vice versa if is 12hrs format. 因此,如果系统时间格式为24小时,则应用程序内部显示的时间也应为24小时,如果系统时间格式为12小时,则反之亦然。

You can retrieve the system time format by using this code: 您可以使用以下代码来检索系统时间格式:

SimpleDateFormat dateFormat = new SimpleDateFormat();
String pattern = dateFormat.toLocalizedPattern(); //if you want the string pattern

There is no way to listen for a time format change action, but giving that this action is always made outside your application, you can put the code in your Activity's / Fragment's onResume() method and change the UI accordingly. 没有办法监听时间格式更改操作,但是鉴于此操作始终在应用程序外部进行,您可以将代码放入Activity的/ Fragment的onResume()方法中,并相应地更改UI。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM