Converting time between time zones
In this section we have written a java program which will take two Time Zone IDs as its argument and then convert the time between provided time zone IDs.
In our program we have firstly created a new date object and then after we have created two time zone class's objects with according to the provided time zone IDs.
TimeZone firstTime = TimeZone.getTimeZone(args);
TimeZone secondTime = TimeZone.getTimeZone(args);
Above lines of code creates two objects of TimeZone as firstTime and secondTime. We have called getTimeZone() method to create these objects.
Here is the full example code of ConvertTimeZone.java as follows:
Compile the ConvertTimeZone.java file and when executing them provide the two Time zone Ids from which to which time is to be converted. Here in above program we have provided two command line arguments as IST and GMT.
C:\DateExample>java ConvertTimeZone IST GMT
-->IST: 10/11/08 4:16 PM
-->GMT: 10/11/08 10:46 AM
Liked it! Share this Tutorial