Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Java Java-conversion Convert GMT to IST

Related Tutorials


 
 

Share on Google+Share on Google+

Convert GMT to IST

Advertisement
In this section, you will learn to convert a GMT to IST format. The GMT stands for Greenwich Mean Time and IST stands for India Standard Time.

Convert GMT to IST

     

In this section, you will learn to convert a GMT to IST format. The GMT stands for Greenwich Mean Time and IST stands for India Standard Time.  

Description of program:

This example helps you in converting a GMT time to IST time on the console. The SimpleDateFormat() constructor uses the given pattern and date format symbols. Here we use the date format as gmtFormat which gets converted to istFormat. Then we have used  getTimeZone() method to get the time of both the zones to be converted. 

India Standard Time is 5.5 hours (5 hours 30 minutes) ahead of Greenwich Mean Time (GMT+5.5). 

Here is the code of program:

import java.util.*;
import java.text.*;
import java.io.*;

public class GMTtoIST{
  public static void main(String args[]){
  Date date = new Date();
  DateFormat istFormat = new SimpleDateFormat();
  DateFormat gmtFormat = new SimpleDateFormat();
  TimeZone gmtTime = TimeZone.getTimeZone("GMT");
  TimeZone istTime = TimeZone.getTimeZone("IST");
  
  istFormat.setTimeZone(gmtTime);
  gmtFormat.setTimeZone(istTime);
  System.out.println("GMT Time: " + istFormat.format(date));
  System.out.println("IST Time: " + gmtFormat.format(date));
  }
}

Output of the program:

C:\unique>javac GMTtoIST.java

C:\unique>java GMTtoIST
GMT Time: 8/4/07 9:49 AM
IST Time: 8/4/07 3:19 PM

C:\unique>

Download this example.

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: August 9, 2007

Related Tutorials

Discuss: Convert GMT to IST   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:3
shankar
December 27, 2011
conversion

need to convert IST to GMT
gautam
April 11, 2012
gmt to ist convert

gmt to ist convert
himanshi kapoor
June 19, 2012
i want all information about gtm and ist

ohh i like it
DMCA.com