如何在android中获取用户日期时间设置

Dee*_*pak 3 android calendar

我有一个Calendar对象,我知道如何使用android.text.format格式化它()如何获取日期和时间的电话设置,以将对象格式化为用户设置的格式.喜欢24小时制,mmm dd yyyy ......

Dee*_*pak 10

我想要的是在单独的TextViews中提供根据用户的首选项和语言环境格式化的日期和时间.

我在DateFormat类中使用静态方法完成了这个:

DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(getApplicationContext()); // Gets system date format
DateFormat timeFormat = android.text.format.DateFormat.getTimeFormat(getApplicationContext()); // Gets system time format

txt1.setText(dateFormat.format(CalendarInstance.getTime())); // format() Returns a string according to the user's preferences (12-hr vs 24-hr) and locale
txt2.setText(timeFormat.format(CalendarInstance.getTime()));
Run Code Online (Sandbox Code Playgroud)