Question

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?

Was it helpful?

Solution

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()));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top