如何在Android中获取用户选择的日期格式?

Uma*_*til 14 format datetime android locale

我一直在研究Android手机用户选择的日期格式问题.我在stackoverlow上经历了几乎所有的问题和答案,并没有得到完美的答案.例如: - 我在手机中选择了dateformat是"星期六,2011年12月31日"但是当我在stackoverflow上使用基于问题的答案: -

DateFormat df = android.text.format.DateFormat.getDateFormat(context.getApplicationContext());
tv.setText(df.format(date));
Run Code Online (Sandbox Code Playgroud)

上面的代码返回06/08/2011(mm/dd/yyyy)格式.但请参阅我在手机上选择的日期格式.我怎样才能得到确切的格式?

Ste*_*man 31

在我正在开发的应用程序中,我使用以下内容,我相信它会满足您的需求

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);
}
Run Code Online (Sandbox Code Playgroud)