cdm/src/main/java/ucar/nc2/units/DateFromString.java
public static Date getDateUsingCompleteDateFormatWithOffset( String dateString, String dateFormatString, int startIndex )
  {
    try {
      SimpleDateFormat dateFormat = new SimpleDateFormat( dateFormatString, Locale.US );
      dateFormat.setTimeZone( TimeZone.getTimeZone( "GMT" ) );

      // We have to cut off the dateString, so that it doesnt grab extra characters.
      // eg  new SimpleDateFormat("yyyyMMdd_HH").parse("20061129_06") -> 2006-12-24T00:00:00Z (WRONG!)
      String s;
      if (startIndex + dateFormatString.length() <= dateString.length())
        s = dateString.substring( startIndex, startIndex + dateFormatString.length());
      else
        s = dateString;

      Date result = dateFormat.parse( s );
      if (result == null)
        throw new RuntimeException("SimpleDateFormat bad ="+dateFormatString+" working on ="+s);
      return result;

    } catch (ParseException e) {
      throw new RuntimeException("SimpleDateFormat = "+dateFormatString+" fails on "+ dateString+ " ParseException:"+e.getMessage());
    } catch (IllegalArgumentException e) {
      throw new RuntimeException("SimpleDateFormat = "+dateFormatString+" fails on "+ dateString+ " IllegalArgumentException:"+e.getMessage());
    }
  }
public static Date getDateUsingCompleteDateFormatWithOffset( String dateString, String dateFormatString, int startIndex )
  {
    try {
      SimpleDateFormat dateFormat = new SimpleDateFormat( dateFormatString, Locale.US );
      dateFormat.setTimeZone( TimeZone.getTimeZone( "GMT" ) );

      // We have to cut off the dateString, so that it doesnt grab extra characters.
      // eg  new SimpleDateFormat("yyyyMMdd_HH").parse("20061129_06") -> 2006-12-24T00:00:00Z (WRONG!)
      String s;
      if (startIndex + dateFormatString.length() <= dateString.length())
        s = dateString.substring( startIndex, startIndex + dateFormatString.length());
      else
        s = dateString;

      Date result = dateFormat.parse( s );
      if (result == null)
        throw new RuntimeException("SimpleDateFormat bad ="+dateFormatString+" working on ="+s);
      return result;

    } catch (ParseException e) {
      throw new RuntimeException("SimpleDateFormat = "+dateFormatString+" fails on "+ dateString+ " ParseException:"+e.getMessage());
    } catch (IllegalArgumentException e) {
      throw new RuntimeException("SimpleDateFormat = "+dateFormatString+" fails on "+ dateString+ " IllegalArgumentException:"+e.getMessage());
    }
  }
Parse the given date string (starting at the given startIndex)  using the
given date format string (as described in java.text.SimpleDateFormat) and
return a Date. Assumes TimeZone is GMT.

@param dateString the String to be parsed
@param dateFormatString the date format String
@param startIndex the index at which to start parsing the date string
@return the Date that was parsed.