Tag Archives: TimeZone

Java : How to convert GMT, CST, IST and PST timezone?

In this article, you will learn to convert a date to GMT, CST, EST and PST format.

  • GMT : Greenwich Mean Time
  • CST : Central Standard Time= GMT-5
  • EST : Eastern Standard Time = GMT-6
  • PST : Pacific Standard Time=GMT-7

This example helps you in converting a date to  GMT, CST, EST and PST time on the console. The SimpleDateFormat() constructor uses the given pattern and date format symbols. Here we use the date format as gmtFormat for date format in GMT timezone same way can convert for CST, EST and PST. Then we have used getTimeZone() method to get the time of both the zones to be converted.

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

public class ConvertTimeZoneFromGMT {

public static void main(String[] args) {
//Current Date and Time
Date date = new Date();

//GMT Format
DateFormat gmtFormat = new SimpleDateFormat();
TimeZone gmtTime = TimeZone.getTimeZone("GMT");
System.out.println("GMT Time: " + gmtFormat.format(date));

//CST Time
DateFormat cstFormat = new SimpleDateFormat();
TimeZone cstTime = TimeZone.getTimeZone("CST");
System.out.println("CST Time: " + cstFormat.format(date));

//EST Time
DateFormat istFormat = new SimpleDateFormat();
TimeZone estTime = TimeZone.getTimeZone("EST");
System.out.println("EST Time: " + estFormat.format(date));

// PST Time
DateFormat pstFormat = new SimpleDateFormat();
TimeZone pstTime = TimeZone.getTimeZone("PST");
System.out.println("PST Time: " + pstFormat.format(date)); 



GMT Time: 3/22/19 8:39 AM
CST Time: 3/22/19 3:39 AM
EST Time: 3/22/19 2:09 PM
PST Time: 3/22/19 1:39 AM

Java : Date Format Locale and Internationalization

java.text.SimpleDateFormat class is subclass for java.text.DateFormat which use to convert String to Date and Date to different formatted String. DateFormat class supports TimeZone and Locale specific conversions also.

In below example you will see conversion of date to different Internationalization date by using Locale in SimpleDateFormat.


package com.date;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
public class DateFormatLocaleAndInternationalization {

// Date formats
private static final String MAIN_DATE_FORMAT = "yyyy-MM-dd'T'hh:mm:ss.SSS'Z'";

public static void main(String[] args) {

Date date = new Date();
System.out.println("Date:" + date);

SimpleDateFormat formatter = new SimpleDateFormat(MAIN_DATE_FORMAT, Locale.CANADA);
System.out.println("CANADA DATE :" + formatter.format(date));

formatter = new SimpleDateFormat(MAIN_DATE_FORMAT, Locale.CANADA_FRENCH);
System.out.println("CANADA FRENCH DATE :" + formatter.format(date));

formatter = new SimpleDateFormat(MAIN_DATE_FORMAT, Locale.GERMANY);
System.out.println("GERMANY :" + formatter.format(date));

formatter = new SimpleDateFormat(MAIN_DATE_FORMAT, Locale.CHINESE);
System.out.println("CHINESE DATE :" + formatter.format(date));
formatter = new SimpleDateFormat(MAIN_DATE_FORMAT, Locale.ITALIAN);
System.out.println("ITALIAN :" + formatter.format(date));

formatter = new SimpleDateFormat(MAIN_DATE_FORMAT, Locale.TAIWAN);
System.out.println("TAIWAN DATE :" + formatter.format(date));




Date:Mon Jul 30 12:01:13 PDT 2018
CANADA DATE :2018-07-30T12:01:13.909Z
CANADA FRENCH DATE :2018-07-30T12:01:13.909Z
GERMANY :2018-07-30T12:01:13.909Z
CHINESE DATE :2018-07-30T12:01:13.909Z
ITALIAN :2018-07-30T12:01:13.909Z
TAIWAN DATE :2018-07-30T12:01:13.909Z