1

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?

giozh
  • 9,868
  • 30
  • 102
  • 183

1 Answers1

3

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()));
anubhava
  • 761,203
  • 64
  • 569
  • 643