Java Date Time - Java Calendar.setTimeZone(TimeZone value)








Syntax

Calendar.setTimeZone(TimeZone value) has the following syntax.

public void setTimeZone(TimeZone value)

Example

In the following code shows how to use Calendar.setTimeZone(TimeZone value) method.

//from   ww  w .  j av a2 s.com
import java.util.Calendar;
import java.util.TimeZone;

public class Main {

   public static void main(String[] args) {

      Calendar cal = Calendar.getInstance();

      
      System.out.println(cal.getTimeZone().getDisplayName());
      
      TimeZone tz = TimeZone.getTimeZone("GMT");

      // set the time zone with the given time zone value and print it
      cal.setTimeZone(tz);
      
      System.out.println(cal.getTimeZone().getDisplayName());
   }
}

The code above generates the following result.