2011-08-08 9 views
13

私は、Android Phoneのユーザーが選択した日付形式の問題に取り組んでいます。 私はstackoverlowに関する多くの質問と回答を終え、完璧な答えを得ていません。たとえば : - 私は電話でDATEFORMATを選択している は「土、2011年12月31日」 あるしかし、私はstackoverflowのに答え基づき、質問として使用: - 上記のコードAndroidでユーザーが選択した日付形式を取得する方法は?

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

は(私の2011年6月8日返しますmm/dd/yyyy)形式で入力します。 しかし、電話で選択した日付の形式を見てください。どうすれば正確なフォーマットを取得できますか?

答えて

27

、するためのライブラリです何この

Date inDate = inFormat.parse(in); 
DateFormat outFormat = android.text.format.DateFormat.getDateFormat(context); 
out=outFormat.format(inDate); 
+0

をお試しくださいこの設定? – KJEjava48

2

DateFormat.getDateFormatは期待どおりに動作します。これは3つの可能なフォーマットのいずれかを返します

  1. MM/DD/YYYY
  2. DD/MM/YYYY
  3. YYYY/MM/DD

私はあなたの"土、2011年12月31日"フォーマットを設定方法がわからないんだけど、私が知っている限り、アンドロイドは前述の3つのフォーマット(設定 - >日付と時刻 - >日付フォーマットの選択)のうちの1つだけを設定することができます。私はあなたが

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); 
} 
1

を必要と何だろうと考えている私は現在、私は次のように使用して開発していたアプリケーションで

enter image description here

関連する問題