TimeZone is an abstract class in Java, which allows us to work with time zone offsets from Greenwhich mean time (GMT), which is also referred to as Coordinated Universal Time (UTC). TimeZone represents a time zone offset, and also figures out daylight savings(Daylight saving time (DST) or summer time is the practice of advancing clocks during the summer months that have more sunlight so that people get up later in the morning and go to bed later at night. Typically clocks are adjusted forward one hour near the start of spring and are adjusted backward in the autumn).
Creating TimeZone instance :
getDefault method of TimeZone creates a TimeZone based on the time zone where the program is running. For example, for a program running in Japan, getDefault creates a TimeZone object based on Japanese Standard Time. Creating TimeZone with a time zone ID : getTimeZone method of TimeZone creates a time zone with a time zone ID. For instance, the time zone ID for the U.S. Pacific Time zone is "America/Los_Angeles" . So, we can get a U.S. Pacific Time TimeZone object with: TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles"); getAvailableIDs method returns an array of supported time zone IDs. You can then choose a supported ID to get a TimeZone. If the time zone we want is not represented by one of the supported IDs, then a custom time zone ID can be specified to produce a TimeZone. The syntax of a custom time zone ID is:
CustomID: GMT Sign Hours : Minutes e.g.,GMT+10:30 GMT Sign Hours Minutes e.g., GMT+0530 GMT Sign Hours e.g., GMT-12 When creating a TimeZone, the specified custom time zone ID is normalized in the following syntax: NormalizedCustomID: GMT Sign TwoDigitHours : Minutes
For example, TimeZone.getTimeZone("GMT-8").getID() returns "GMT-08:00".Constructor : TimeZone have only one constructor. public TimeZone() This constructor is the single constructor for invocation by subclass Methods :
TimeZoneDemo CODE import java.util.*; OUTPUT India Standard Time DESCRIPTION In the above program we have created a calendar instance at LINE A and a TimeZone instance with India Standard Time zone. At LINE C we dislplayed the name of the time zone using THINGS TO TRY
|