当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Java SimpleTimeZone setRawOffset()用法及代码示例


SimpleTimeZone类的setRawOffset()方法用于将基本时区偏移量设置为GMT。将偏移量添加到UTC以获取本地时间。

用法:

public void setRawOffset(int offsetMillis)

参数:该函数接受单个参数offsetMillis,该参数指定GMT的给定基准时区偏移量。


返回值:该方法没有返回值。

异常:该函数不会引发任何异常。

下面的程序演示了上述函数:

示例1:

// program to demonstrate the 
// function java.util.SimpleTimeZone.setRawOffset() 
  
import java.util.*; 
  
public class GFG { 
  
    public static void main(String[] args) 
    { 
  
        // create simple time zone object 
        SimpleTimeZone obj 
            = new SimpleTimeZone(500, "GMT"); 
  
        // printing RawOffset value 
        System.out.println("Inittally RawOffset is = "
                           + obj.getRawOffset()); 
  
        // setting RawOffset on object obj 
        obj.setRawOffset(6000000); 
        System.out.println("RawOffset "
                           + "set to 6000000"); 
  
        // printing RawOffset value 
        System.out.println("Current RawOffset is = "
                           + obj.getRawOffset()); 
    } 
}
输出:
Inittally RawOffset is = 500
RawOffset set to 6000000
Current RawOffset is = 6000000

示例2:

// program to demonstrate the 
// function java.util.SimpleTimeZone.setRawOffset() 
  
import java.util.*; 
  
public class GFG { 
  
    public static void main(String[] args) 
    { 
  
        // create simple time zone object 
        SimpleTimeZone obj 
            = new SimpleTimeZone(800, "GMT"); 
  
        // printing RawOffset value 
        System.out.println("Inittally RawOffset is = "
                           + obj.getRawOffset()); 
  
        // setting RawOffset on object obj 
        obj.setRawOffset(8000000); 
        System.out.println("RawOffset "
                           + "set to 8000000"); 
  
        // printing RawOffset value 
        System.out.println("Current RawOffset is = "
                           + obj.getRawOffset()); 
    } 
}
输出:
Inittally RawOffset is = 800
RawOffset set to 8000000
Current RawOffset is = 8000000


相关用法


注:本文由纯净天空筛选整理自Twinkl Bajaj大神的英文原创作品 SimpleTimeZone setRawOffset() method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。