I am in U.S. Eastern Standard Time Zone (4 hours behind GMT during daylight savings time, or 5 hours behind GMT during eastern standard time).
My web application is running on Weblogic server, the server is using GMT system time zone.
I need to convert input from UI, which is in EST
String format ( "9/1/2005 00:00"), to GMT Timestamp object (9/1/2005 04:00).
How can I do it? I tried this and it did not work:
import java.util.*;
import java.text.SimpleDateFormat;
public class TZ1 {
public static void main(String[] args) {
TimeZone tz = TimeZone.getTimeZone("US/Eastern");
TimeZone GMT_TIME_ZONE = TimeZone.getTimeZone("GMT");
Calendar estCalendar = Calendar.getInstance(tz);
Calendar gmtCalendar = Calendar.getInstance(GMT_TIME_ZONE);
String dateString = "9/1/2005";
String formatString = "MM/dd/yyyy";
SimpleDateFormat eptDateFormat = new SimpleDateFormat(formatString);
eptDateFormat.setTimeZone(tz);
SimpleDateFormat gmtDateFormat = new SimpleDateFormat(formatString);
gmtDateFormat.setTimeZone(GMT_TIME_ZONE);
try {
System.out.println("dateString is: " + dateString);
//Date resultDate1 = eptDateFormat.parse(dateString);
//System.out.println("resultDate1 is: " + resultDate1);
Date resultDate2 = gmtDateFormat.parse(dateString);
System.out.println("resultDate2 is: " + resultDate2);
} catch (Exception e) {
}
}
}