cdm/src/main/java/ucar/nc2/units/DateFromString.java
public static Date getDateUsingDemarkatedMatch( String dateString, String dateFormatString, char demark )
  {
    // extract the match string
    int pos1 = dateFormatString.indexOf( demark);
    int pos2 = dateFormatString.indexOf( demark, pos1+1);
    if ((pos1 < 0) || (pos2 < 0)) {
      logger.error("Must delineate Date between 2 '#' chars, dateFormatString = '"+ dateFormatString+"'", new Throwable());
      return null;
    }
    String match = dateFormatString.substring(pos1+1, pos2);

    int pos3 = dateString.indexOf(match);
    if (pos3 < 0) return null;

    if (pos1 > 0) {  // pos1 > 0, date is before the match: "yyyyMMddHH#/wrfout_d01_#"
      dateFormatString = dateFormatString.substring(0, pos1);
      dateString = dateString.substring(pos3-dateFormatString.length(), pos3);

    }  else {        // pos1 == 0, date is after the match: "#wrfout_d01_#yyyy-MM-dd_HHmm"
      dateFormatString = dateFormatString.substring(pos2+1);
      dateString = dateString.substring(pos3+match.length());
    }

    // any leading or trailing "." in the dateFormatString means trim
    int posDot1 = 0;
    while (dateFormatString.charAt(posDot1) == '.')
      posDot1++;
    int posDot2 = dateFormatString.length();
    while (dateFormatString.charAt(posDot2-1) == '.')
      posDot2--;
    if (posDot1 != 0 || posDot2 != dateFormatString.length()) {
      dateFormatString = dateFormatString.substring(posDot1, posDot2);
      dateString = dateString.substring(posDot1, posDot2);
    }

    return getDateUsingCompleteDateFormatWithOffset( dateString, dateFormatString, 0 );
  }
public static Date getDateUsingDemarkatedMatch( String dateString, String dateFormatString, char demark )
  {
    // extract the match string
    int pos1 = dateFormatString.indexOf( demark);
    int pos2 = dateFormatString.indexOf( demark, pos1+1);
    if ((pos1 < 0) || (pos2 < 0)) {
      logger.error("Must delineate Date between 2 '#' chars, dateFormatString = '"+ dateFormatString+"'", new Throwable());
      return null;
    }
    String match = dateFormatString.substring(pos1+1, pos2);

    int pos3 = dateString.indexOf(match);
    if (pos3 < 0) return null;

    if (pos1 > 0) {  // pos1 > 0, date is before the match: "yyyyMMddHH#/wrfout_d01_#"
      dateFormatString = dateFormatString.substring(0, pos1);
      dateString = dateString.substring(pos3-dateFormatString.length(), pos3);

    }  else {        // pos1 == 0, date is after the match: "#wrfout_d01_#yyyy-MM-dd_HHmm"
      dateFormatString = dateFormatString.substring(pos2+1);
      dateString = dateString.substring(pos3+match.length());
    }

    // any leading or trailing "." in the dateFormatString means trim
    int posDot1 = 0;
    while (dateFormatString.charAt(posDot1) == '.')
      posDot1++;
    int posDot2 = dateFormatString.length();
    while (dateFormatString.charAt(posDot2-1) == '.')
      posDot2--;
    if (posDot1 != 0 || posDot2 != dateFormatString.length()) {
      dateFormatString = dateFormatString.substring(posDot1, posDot2);
      dateString = dateString.substring(posDot1, posDot2);
    }

    return getDateUsingCompleteDateFormatWithOffset( dateString, dateFormatString, 0 );
  }
Parse the given date string (between the demarcation characters)
using the given date format string (as described in
java.text.SimpleDateFormat) and return a Date.
<pre>
Example:
dateString =  /data/anything/2006070611/wrfout_d01_2006-07-06_080000.nc
dateFormatString =                    #wrfout_d01_#yyyy-MM-dd_HHmm
would extract the date 2006-07-06T08:00

dateString =  /data/anything/2006070611/wrfout_d01_2006-07-06_080000.nc
dateFormatString =          yyyyMMddHH#/wrfout_d01_#
would extract the date 2006-07-06T11:00
</pre>

@param dateString the String to be parsed
@param dateFormatString the date format String
@param demark the demarkation character
@return the Date that was parsed.