0

I'm having trouble fixing the issue. I'm trying to parse a date string 2013-05-23T19:00:00GMT-00 into the StandardFormat which is yyyy-MM-dd'T'HH:mm:ssz but I always get a ParseException at position 25.

    // Get a human readable format.
    DateFormat dateFormat = DateTime.getStandardFormat();

    // Subtract a full hour from the time passed in.
    final int HOUR_IN_MINUTES = 3600;
    DateTime dateTimeLess1Hour = aDateTime.minus(HOUR_IN_MINUTES, 0);

    // Convert the DateTime, less exactly one hour, to a string.
    String timeLess1String = dateFormat.format(DateTime.toDate(dateTimeLess1Hour));

    // Split the string to distinguish the time part
    String date = timeLess1String.substring(0, 10);
    String time = timeLess1String.substring(11);

    String[] hhMMss = time.split(":");

    String hourOnHourDate = date + "T" + hhMMss[0] + ":00:00" + hhMMss[2].substring(2);

    Date inDateFormat = null;

    // Convert the string into a Date object
    inDateFormat = dateFormat.parse(hourOnHourDate);

    // Convert the Date into a DateTime object.
    return new DateTime(inDateFormat);

The error message says Unparseable date: 2013-05-23T19:00:00GMT-00

Adarsh
  • 3,613
  • 2
  • 21
  • 37
Alessandro
  • 309
  • 5
  • 23

1 Answers1

0

The position 25 indicates the beginning of the GMT part which is the one you are trying parse using the letter z. If you are sure that your time zone will always be GMT, then you can put it as a fixed string as the following:

yyyy-MM-dd'T'HH:mm:ss'GMT'

If the input time zone will differ from time to time, then separate it.

String zone = inputTime.substring(startPosition, endPosition);

And set the time zone in a separate line using zone string

Sami Eltamawy
  • 9,874
  • 8
  • 48
  • 66