0
  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??

shmosel
  • 49,289
  • 6
  • 73
  • 138
  • 2
    We don't know what time zone you're using, which makes it basically impossible to answer this. What does `tz.getID()` show in each case? Please provide a [mcve] which shows the time zone and the value of `offsetInMillis`, explaining what you *expect* the value to be and why. – Jon Skeet Nov 22 '17 at 06:43
  • What do you consider the "correct" offset? If you want a specific offset, don't use the system default. – shmosel Nov 22 '17 at 07:05

0 Answers0