4

ユーザーの場所と現在のデバイス時間に関係なく、ドイツの現在の時間を取得するにはどうすればよいですか?

    Calendar buttoncal = Calendar.getInstance();
    String tdate = new SimpleDateFormat("dd.MM",Locale.GERMANY).format(buttoncal.getTime());
    String tday  = new SimpleDateFormat("EEEE",Locale.GERMANY).format(buttoncal.getTime());


    one_date.setText(tdate.toString());
    one_day.setText(tday);
4

3 に答える 3

3

使用する必要があるタイムゾーンを指定できます。

Calendar c = Calendar.getInstance(TimeZone.getTimeZone("Europe/Berlin"));

利用可能なタイムゾーンのリストについては: TimeZone.getAvailableIDs().

注: のロケールは、そのロケールでSimpleDateFormat文字列を読み取り/フォーマットするために使用されます。たとえば、ドイツ語のロケールを使用すると、月/日の名前がドイツ語で出力されます。しかし、タイムゾーンとは何の関係もありません。

于 2013-04-13T11:25:45.273 に答える
1

これを使用してみてください:

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.GERMANY); 
Date date = new Date();
dateFormat.format(date);

「yyyy-MM-dd HH:mm」の形式で「日付」を取得します。次に、.split() を使用して、スペースを区切り文字として使用して、返された文字列形式を分割できます。何かのようなもの:

String[] str_array = date.toString().split(" ");
String time = str_array[1];
于 2013-04-16T10:18:30.050 に答える
0

ここで提案したように、代わりにandroid.text.format.Timeを使用してください。

于 2013-04-16T13:26:20.023 に答える