Home » Java programming language

Java TimeZone setRawOffset() Method with Example

TimeZone Class setRawOffset() method: Here, we are going to learn about the setRawOffset() method of TimeZone Class with its syntax and example.
Submitted by Preeti Jain, on March 13, 2020

TimeZone Class setRawOffset() method

  • setRawOffset() method is available in java.util package.
  • setRawOffset() method is used to set the raw base time zone offset in ms.
  • setRawOffset() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
  • setRawOffset() method does not throw an exception at the time of set raw offset in milliseconds.

Syntax:

    public abstract void setRawOffset(int offset_ms);

Parameter(s):

  • int offset_ms – represents the base time zone offset to GMT.

Return value:

The return type of the method is void, it returns nothing.

Example:

// Java program to demonstrate the example 
// of void setRawOffset(int offset_ms) method 
// of TimeZone 

import java.util.*;

public class SetRawOffSetOfTimeZone {
    public static void main(String args[]) {
        // Instantiates TimeZone object
        TimeZone tz = TimeZone.getTimeZone("Africa/Asmera");

        // Display Timezone Offset
        System.out.println("tz.getRawOffset(): " + tz.getRawOffset());

        // By using setRawOffset() method is to
        // set the offset for this time zone tz
        // Africa/Asmera
        tz.setRawOffset(1100000);

        // Display tz
        System.out.println("tz.setID(Africa/Asmera): " + tz.getRawOffset());
    }
}

Output

tz.getRawOffset(): 10800000
tz.setID(Africa/Asmera): 1100000


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.