質問

I would set a TimeZone for Calendar instance but i'm not able to do it. I've try with:

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

(i've used "America/Rosario" randomly), but i obtain always my current time. What's the right mode to do that?

役に立ちましたか?

解決

You should set timezone in DateFormat object:

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()));
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top