I know there are other similar questions, but I came up with my own way to get the current time in a specific time zone, so I just wanted to confirm whether it was right or not, or gotchas I didn't care.
Calendar cal = Calendar.getInstance();
TimeZone tz = TimeZone.getTimeZone("GMT");
cal.setTimeInMillis(calendar.getTimeInMillis()
+ tz.getOffset(calendar.getTimeInMillis())
- TimeZone.getDefault().getOffset(calendar.getTimeInMillis()));
Is this indicated correctly? I did my own test and it seemed to work as expected, but just wanted to confirm it again with experts at Stack Overflow.
source
share