1

Possible Duplicate:
Timezone conversion

I have to convert given time and timezone with some other timezone using Java code.

For Example :

I have to convert 28 Sept 2:00 PM IST in Canada timezone with considering DST (Day Light Saving Time) as well.

Can someone help me?

Community
  • 1
  • 1
VJS
  • 2,891
  • 7
  • 38
  • 70
  • Check this [link](http://code.google.com/p/h2database/source/browse/trunk/h2/src/main/org/h2/util/DateTimeUtils.java) – devsathish Sep 28 '12 at 08:28

5 Answers5

1

Try getTimeZone() and setTimeZone() along with Calendar class

TimeZone oztz = TimeZone.getTimeZone("Canada/Atlantic");
Calendar datetime = Calendar.getInstance( oztz );

See this link for all Time-Zones :

http://snipplr.com/view/23131/timezone-enum/

Kumar Vivek Mitra
  • 33,294
  • 6
  • 48
  • 75
0

The Calendar class has built in methods for doing the conversion.

You can set the desired timezone with setTimeZone.

Also see the getTimeZoneOffset from the Date class.

gh.
  • 339
  • 1
  • 3
  • 20
0

Probably you are looking for something like this : Converting Times Between Time Zones

MD. Sahib Bin Mahboob
  • 20,246
  • 2
  • 23
  • 45
0

You could use JodaTime and its support for different timezones.

Namely, if you know you have string ISO format or a specific known format (like it looks like), you could do something like:

DateTimeFormatter fmt = ISODateTimeFormat.dateTime().withZone("Asia/Kolkata");
DateTime newDate = fmt.parseDateTime([your input date]);
// You can manipulate your date here...
String newString = fmt.withZone("Canada/Atlantic").print();

This handles internally all Timezone matters, included DST.

mdm
  • 3,928
  • 3
  • 27
  • 43
0

Simple way is set Datetime and Timezone to Calender and getTime. Below is sample code which will set Timezone and user specific time.

Date date =new Date(2012,9,28,2,00,00); //Set time to Date
        Calendar calendar = new GregorianCalendar(TimeZone.getTimeZone("Canada/Atlantic"));
        calendar.setTime(date);

        System.out.println("Timezone :: " + calendar.getTimeZone());
        System.out.println("Time :: " + calendar.getTime());

Output:

 Timezone :: sun.util.calendar.ZoneInfo[id="Canada/Atlantic",offset=-14400000,dstSavings=3600000,useDaylight=true,transitions=228,lastRule=java.util.SimpleTimeZone[id=Canada/Atlantic,offset=-14400000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=3,startMonth=3,startDay=1,startDayOfWeek=1,startTime=7200000,startTimeMode=0,endMode=2,endMonth=9,endDay=-1,endDayOfWeek=1,endTime=7200000,endTimeMode=0]]
    Time :: Mon Oct 28 02:00:00 GMT 3912

You will get all information from TimeZone useDaylight(true/false), dstSaving(1 hour for canada) For more functionality of TimeZone please refer below link: http://biese.wordpress.com/2006/10/23/java-daylight-saving-time-and-time-zone/

Here is link to get DayLightSavingTime information: http://timeanddate.com/worldclock/clockchange.html?n=1187&year=2012