Creating iCal with correct timezone

Greg Allen
  • Greg Allen

    Greg Allen - 2013-03-05

    I am having trouble creating an event with the correct start time based on the timezone information.  For example, I have a DateTime object with milliseconds set to 1363629600, which corresponds to the following date:

    GMT: Mon, 18 Mar 2013 18:00:00 UTC
    Your time zone: Monday, March 18, 2013 2:00:00 PM GMT-4

    I now want to create this event in iCal. I have tried the following code fragment:

    TimeZone timezone = registry.getTimeZone("America/New_York");
    DateTime dtStart = new DateTime();
    master.getProperties().add(new DtStart(dtStart));

    However, when I generate the iCal, I get the following:


    As you can see, the time is an hour earlier than it should be.

    I think this must be a timezeone issue, but I can't see what I am doing wrong. It's like the timezone being used to calculate the DtStart time is not using the daylight savings offset (EDT), but rather EST.

    Can anybody help?


    • Greg
  • Greg Allen

    Greg Allen - 2013-03-07

    Well, I have learned a little more but still don't have a solution.

    I added the following code to what I posted earlier:

    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String s = formatter.format(master.getStartDate().getDate());

    When I look at the string in the debugger, it is what I expect: 2013-03-18 14:00:00.

    So it appears the DtStart property is correct.

    However, when I generate the ical using the Calendar.toString() method, the time comes out as 13:00. I've tried adding the VTIMEZONE component to the calendar and everything else I can think of, but nothing seems to fix this.

    Can anyone help????


  • Greg Allen

    Greg Allen - 2013-03-08

    Well, another interesting piece of information.

    I added a line of code to get the toString() value of my date, like this:

    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String s = formatter.format(master.getStartDate().getDate());
    String x = master.getStartDate().toString();

    Now at this point s has the value "2013-03-18 14:00:00" while x has "DTSTART;TZID=America/New_York:20130318T130000".

    The x value is wrong!  It appears as though the toString method doesn't take into account the timezone.

    Is there any way to correct this?

  • Greg Allen

    Greg Allen - 2013-03-10

    Well, I found a way to make this work.

    If I use either the DtStart contructor with a string argument or the method DtStart.setValue, I can set the value and it is correct when I generate the iCal.

    Hopefully this well help someone else.

    Setting the DtStart value using a DateTime object does not appear to work. I believe this is a bug.

  • Greg Allen

    Greg Allen - 2013-03-12

    I opened a bug for this issue:

    3607533 Generated iCal does not take timezone info into account     Open  2013-03-10   fortuna


Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks