我有一个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)
归档时间: |
|
查看次数: |
2828 次 |
最近记录: |