0

I've a date in following format

Wed Jun 10 07:00:00 IST 2015

Which i need to convert to GST time zone.Please help me to resolve the issue.

The output would be Wed Jun 10 05:30:00 IST 2015 Thanks in advance

AKR
  • 29
  • 2
  • 9

1 Answers1

-1

Examples of this are all over the web. Here's an example I shamelessly plucked from here. You'll have to modify a bit to fit your formatting, but the conversion is there.

Calendar calendar = Calendar.getInstance();
TimeZone fromTimeZone = calendar.getTimeZone();
TimeZone toTimeZone = TimeZone.getTimeZone("CST");

calendar.setTimeZone(fromTimeZone);
calendar.add(Calendar.MILLISECOND, fromTimeZone.getRawOffset() * -1);
if (fromTimeZone.inDaylightTime(calendar.getTime())) {
    calendar.add(Calendar.MILLISECOND, calendar.getTimeZone().getDSTSavings() * -1);
    }

    calendar.add(Calendar.MILLISECOND, toTimeZone.getRawOffset());
    if (toTimeZone.inDaylightTime(calendar.getTime())) {
        calendar.add(Calendar.MILLISECOND, toTimeZone.getDSTSavings());
    }

    System.out.println(calendar.getTime());`
Community
  • 1
  • 1
JShell
  • 624
  • 2
  • 7
  • 22