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



Home Java Java-conversion Convert GMT to CST

Related Tutorials


 
 

Share on Google+Share on Google+

Convert GMT to CST

Advertisement
In this section, you will learn to convert a GMT to CST format.

Convert GMT to CST

     

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

Description of program:

This example helps you in converting a GMT time to CST 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 cstFormat. Then we have used  getTimeZone() method to get the time of both the zones to be converted. 

Central Time - USA + Canada

Central Standard Time (CST) = GMT-6
Central Daylight Time (CDT) = GMT-5

Here is the code of program:

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

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

Output of the program:

C:\unique>javac GMTtoCST.java

C:\unique>java GMTtoCST
GMT Time: 8/4/07 9:44 AM
CST Time: 8/4/07 4:44 AM

C:\unique>

Download this example.

Advertisements

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: June 9, 2009

Related Tutorials

Discuss: Convert GMT to CST   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com