Java SimpleTimeZone setDSTSavings() Method



Description

The Java SimpleTimeZone setDSTSavings(int millisSavedDuringDST) method is used to set the amount of time in milliseconds that the clock is advanced during daylight saving time.

Declaration

Following is the declaration for java.util.SimpleTimeZone.setDSTSavings() method.

public void setDSTSavings(int millisSavedDuringDST)

Parameters

millisSavedDuringDST − This is the the number of milliseconds the time is advanced with respect to standard time.

Return Value

NA

Exception

NA

Setting DST Savings for a SimpleTimeZone Instance of Indian Zone

The following example shows the usage of Java SimpleTimeZone setDSTSavings() method to advance the time with respect to standard time. We've created a SimpleTimeZone using India. Then we've advanced the time using setDSTSavings() method and printed the status using getDSTSavings() method.

package com.tutorialspoint;

import java.util.Calendar;
import java.util.SimpleTimeZone;

public class SimpleTimeZoneDemo {
   public static void main( String args[] ) {
      
      // create simple time zone object
      SimpleTimeZone stobj = new SimpleTimeZone(-28800000, "India", 
      Calendar.MAY, 1,-Calendar.SUNDAY, 7200000, Calendar.OCTOBER, -1,
      Calendar.MONDAY, 7200000, 3600000);

      // setting DST saving time
      stobj.setDSTSavings(5400000); 

      // checking the value      
      System.out.println("DST saving value : " + stobj.getDSTSavings());
   }     
}

Output

Let us compile and run the above program, this will produce the following result.

DST saving value : 5400000

Setting DST Savings for a SimpleTimeZone Instance of GMT Zone

The following example shows the usage of Java SimpleTimeZone setDSTSavings() method to advance the time with respect to standard time. We've created a SimpleTimeZone using GMT. Then we've advanced the time using setDSTSavings() method and printed the status using getDSTSavings() method.

package com.tutorialspoint;

import java.util.Calendar;
import java.util.SimpleTimeZone;

public class SimpleTimeZoneDemo {
   public static void main( String args[] ) {
      
      // create simple time zone object
      SimpleTimeZone stobj = new SimpleTimeZone(-28800000, "GMT", 
      Calendar.MAY, 1,-Calendar.SUNDAY, 7200000, Calendar.OCTOBER, -1,
      Calendar.MONDAY, 7200000, 3600000);

      // setting DST saving time
      stobj.setDSTSavings(5400000); 

      // checking the value      
      System.out.println("DST saving value : " + stobj.getDSTSavings());
   }     
}

Output

Let us compile and run the above program, this will produce the following result.

DST saving value : 5400000

Setting DST Savings for a SimpleTimeZone Instance of BST Zone

The following example shows the usage of Java SimpleTimeZone setDSTSavings() method to advance the time with respect to standard time. We've created a SimpleTimeZone using BST. Then we've advanced the time using setDSTSavings() method and printed the status using getDSTSavings() method.

package com.tutorialspoint;

import java.util.Calendar;
import java.util.SimpleTimeZone;

public class SimpleTimeZoneDemo {
   public static void main( String args[] ) {
      
      // create simple time zone object
      SimpleTimeZone stobj = new SimpleTimeZone(-28800000, "BST", 
      Calendar.MAY, 1,-Calendar.SUNDAY, 7200000, Calendar.OCTOBER, -1,
      Calendar.MONDAY, 7200000, 3600000);

      // setting DST saving time
      stobj.setDSTSavings(5400000); 

      // checking the value      
      System.out.println("DST saving value : " + stobj.getDSTSavings());
   }     
}

Output

Let us compile and run the above program, this will produce the following result.

DST saving value : 5400000
java_util_simpletimezone.htm
Advertisements