Java SimpleTimeZone.setRawOffset(int offsetMillis) method example

In this tutorial, You will learn how to set the GMT offset of this time zone using Java SimpleTimeZone.setRawOffset(int offsetMillis) method . It sets the base time zone offset to GMT. This is the offset to add to UTC to get local time.

Sets the base time zone offset to GMT. This is the offset to add to UTC to get local time.

syntax

public void setRawOffset(int offsetMillis)

Parameters

offsetMillis - the given base time zone offset to GMT.

Java SimpleTimeZone setRawOffset(int offsetMillis) example

  • new SimpleTimeZone(100, "GMT"); It will construct a SimpleTimeZone with the given base time zone.
  • simpleTimeZone.setRawOffset(7200000); It will set the base time zone offset.
  • simpleTimeZone.getRawOffset(); It returns the GMT offset for this time zone.
  • Print the offset value.
package com.technicalkeeda;

import java.util.SimpleTimeZone;

public class App {

    public static void main(String[] args) {

        SimpleTimeZone simpleTimeZone = new SimpleTimeZone(100, "GMT");

        System.out.println("Initial raw offset: " + simpleTimeZone.getRawOffset());

        simpleTimeZone.setRawOffset(7200000);

        System.out.println("After setRawOffset is :- " + simpleTimeZone.getRawOffset());
    }
}

output

Initial raw offset: 100
After setRawOffset is :- 7200000