1

Calendar インスタンスの TimeZone を設定しますが、できません。私は試してみました:

DateFormat dateFormat = new SimpleDateFormat("dd//MM/yyyy HH:mm:ss");
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("America/Rosario"));
System.out.println(cal.getTime());

(「アメリカ/ロザリオ」をランダムに使用しました)が、常に現在の時刻を取得します。それを行うための正しいモードは何ですか?

4

1 に答える 1

3

オブジェクトにタイムゾーンを設定する必要がありDateFormatます:

DateFormat df = new SimpleDateFormat("dd//MM/yyyy HH:mm:ss", Locale.getDefault());
df.setTimeZone(TimeZone.getTimeZone("America/Rosario"));

// Will print the formatted date-time in the America/Rosario timezone  
System.out.println(df.format(new Date()));
于 2013-10-17T08:09:17.373 に答える