TimeZone tz = TimeZone.getDefault();
Calendar cal = java.util.GregorianCalendar.getInstance(tz);
int offsetInMillis = tz.getOffset(cal.getTimeInMillis());
String offset = String.format("%02d:%02d", Math.abs(offsetInMillis / 3600000), Math.abs((offsetInMillis / 60000) % 60));
offset = (offsetInMillis >= 0 ? "+" : "-") + offset;
I've tried the above code to get the offset, but the problem is that my application runs on a VM; when I run the above code in my VM it gets me the correct offset but when I run the same method in my local machine to VM it gives me VMs offset (which is wrong).
Is there any way I can get the correct offset??