Convert GMT to PST
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
code
Code:
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
Code:
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>
Bookmarks