Convert EST Date Time to IST Date Time

Code:

package com.letscodesomething;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

/**
* @author    V.Santhosh
* @version    1.7
*/
public class ConvertEST2IST {
public static String DATE_EST_DATE_FORMAT = “yyyy-MM-dd HH:mm:ss”;
public static String TIME_ZONE_EST = “America/New_York”;
public static String DATE_IST_DATE_FORMAT = “dd-MM-yyyy hh:mm a”;
public static String TIME_ZONE_IST = “Asia/Calcutta”;

public static void main(String args[]){
String estDateTime = “2017-02-03 04:56:51”;
String istDateTime = “”;
ConvertEST2IST obj = new ConvertEST2IST();
istDateTime = obj.getIST_Date_From_EST_Date_Time(estDateTime);
System.out.println(“The given EST date time : “+estDateTime);
System.out.println(“Equivalent IST date time : “+istDateTime);
}
public String getIST_Date_From_EST_Date_Time(String estDateTimeStr){
String istDate = “”;
try{
SimpleDateFormat estDateTimeFormat = new SimpleDateFormat(DATE_EST_DATE_FORMAT);
estDateTimeFormat.setTimeZone(TimeZone.getTimeZone(TIME_ZONE_EST));
String estDateTimeString = estDateTimeStr; //(EST)
Date estDateTime = estDateTimeFormat.parse(estDateTimeString);

SimpleDateFormat istDateFormat = new SimpleDateFormat(DATE_IST_DATE_FORMAT);
istDateFormat.setTimeZone(TimeZone.getTimeZone(TIME_ZONE_IST));

istDate = istDateFormat.format(estDateTime);

}catch(Exception e){
System.out.println(“EST to IST Time Zone Conversion Causes Exception : “+e.getMessage());
e.printStackTrace();
}
return istDate;
}
}

 

Output:

The given EST date time : 2017-02-03 04:56:51
Equivalent IST date time : 03-02-2017 03:26 PM

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s