문제

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