Avoid Time Zone Codes
Avoid those 3 or 4 letter codes for time zones. They are neither standardized nor unique. For example, the IST
you cite as "Indian Standard Time" is also "Irish Standard Time". Plus they are confusing when in fact you may mean "Summer Time"/"Daylight Saving Time". Instead use proper time zone names, usually made up of a country plus primary city.
Use Sensible Formats For Date-Time Strings
That format "Wed Mar Thu 21:00:00 IST 2014" is not good. Besides being wrong (looks like you typed "Wed" or "Thu" where you should have a day-of-month number), it uses the 3-4 letter code, contains superfluous data (day of week), and assumes English readers. When moving date-time values around as text, use the sensible ISO 8601 format: YYYY-MM-DDTHH:MM:SS.sssZ
such as 2014-03-04T23:20:28Z
.
If changing that format is out of your control, you'll have to determine all the possible 3-4 letter codes that may be used in your data sets and see if your date-time library can handle them.
Avoid java.util.Date/Calendar
The java.util.Date and .Calendar classes are notoriously troublesome. They are outmoded as of Java 8 with the new java.time package. That package is based on the Joda-Time library. Use either Joda-Time or java.time.
Joda-Time
Note that in contrast to java.util.Date, a Joda-Time DateTime object truly knows its assigned time zone.
Here's some Joda-Time 2.3 example code.
String inputIso = "2014-03-19T21:00:00+05:30";
DateTimeZone timeZoneIndia = DateTimeZone.forID( "Asia/Kolkata" );
DateTime dateTimeIndia = new DateTime( inputIso, timeZoneIndia );
// Adjust to Korea Time.
DateTimeZone timeZoneKorea = DateTimeZone.forID( "Asia/Seoul" );
DateTime dateTimeKorea = dateTimeIndia.withZone( timeZoneKorea );
// Adjust to UTC (GMT).
DateTime dateTimeUtc = dateTimeKorea.withZone( DateTimeZone.UTC );
String inputLame = "Thu Mar 20 21:00:00 KST 2014";
DateTimeZone timeZone = null;
if( inputLame.contains( "IST" )) { // Assume IST = India time.
timeZone = DateTimeZone.forID( "Asia/India" );
inputLame = inputLame.replace( " IST ", " ");
}
if( inputLame.contains( "KST" )) { // Assume KST = Korea time.
timeZone = DateTimeZone.forID( "Asia/Seoul" );
inputLame = inputLame.replace( " KST ", " ");
}
DateTimeFormatter formatter = DateTimeFormat.forPattern( "EEE MMM dd HH:mm:ss yyyy" ).withZone( timeZone ).withLocale( java.util.Locale.ENGLISH );
DateTime dateTimeLame = formatter.parseDateTime( inputLame );
Dump to console…
System.out.println( "dateTimeIndia: " + dateTimeIndia );
System.out.println( "dateTimeKorea: " + dateTimeKorea );
System.out.println( "dateTimeUtc: " + dateTimeUtc );
System.out.println( "dateTimeLame: " + dateTimeLame );
When run…
dateTimeIndia: 2014-03-19T21:00:00.000+05:30
dateTimeKorea: 2014-03-20T00:30:00.000+09:00
dateTimeUtc: 2014-03-19T15:30:00.000Z
dateTimeLame: 2014-03-20T21:00:00.000+09:00