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



Home Java Java-conversion Convert GMT to PST

Related Tutorials


 
 

Share on Google+Share on Google+

Convert GMT to PST

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

Convert GMT to PST

     

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

Description of program:

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

Pacific Standard Time (PST) = GMT-8

Pacific Daylight Time (PDT) = GMT-7

Here is the code of program:

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

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

Output of the program:

C:\unique>javac GMTtoPST.java

C:\unique>java GMTtoPST
GMT Time: 8/4/07 9:54 AM
PST Time: 8/4/07 2:54 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: December 15, 2008

Related Tutorials

Discuss: Convert GMT to PST  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:2
aliahmad
November 28, 2011
resharch

I know how to covert GMT to PST thanks
nvrijn
January 26, 2012
GMT converter

The example is wrong, and as a result I almost missed a meeting. PST is GMT-8 ... so how is 9:54-8 = 2:54??
DMCA.com