如何获得用户选择的日期格式的Andr​​oid? [英] How to get user-selected date format in Android?

查看:123
本文介绍了如何获得用户选择的日期格式的Andr​​oid?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力通过用户在Android手机选定的日期格式问题。 我已经经历了几乎很多的问题和答案了对stackoverlow和还没有得到完美的答案。 例如:- 我选择的日期格式的手机是星期六,2011年12月31 但是,当我作为基础的问题回答了计算器: -

I have been working on problem of date format selected by users in the Android Phone. I have gone through almost many question and answers on the stackoverlow and havent got the perfect answer. For example:- I have selected dateformat in phone is "Sat, 31 Dec 2011" But when I used as based question answered on stackoverflow:-

DateFormat df = android.text.format.DateFormat.getDateFormat(context.getApplicationContext());
tv.setText(df.format(date));

以上code返回我2011年6月8日(MM / DD / YYYY)的格式。 但见我选择手机上的日期格式。我怎样才能得到确切的格式?

Above code returns me 06/08/2011 (mm/dd/yyyy) format. But see the date format i selected on phone. How can i get the exact format?

推荐答案

在一个应用程序,我目前正在开发我用下面的,我相信会做什么,你需要

In an application I'm currently developing I use the following, which I believe will do what you require

final String format = Settings.System.getString(getContentResolver(), Settings.System.DATE_FORMAT);
if (TextUtils.isEmpty(format)) {
  dateFormat = android.text.format.DateFormat.getMediumDateFormat(getApplicationContext());
} else {
  dateFormat = new SimpleDateFormat(format);
}

这篇关于如何获得用户选择的日期格式的Andr​​oid?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆