public static Date stringToDate(String strDate) throws ParseException {
  int[] diffTime=null;
  boolean plusTime=true;
  int idxT=strDate.indexOf('T');
  if (idxT == -1) {
    throw new ParseException("Invalid Date Format",0);
  }
  int idxDiffUTC=strDate.indexOf('-',idxT);
  if (idxDiffUTC == -1) {
    idxDiffUTC=strDate.indexOf('+',idxT);
    plusTime=false;
  }
  if (idxDiffUTC != -1) {
    diffTime=getDiffTime(strDate,idxDiffUTC);
    strDate=strDate.substring(0,idxDiffUTC);
  }
  char lastChar=strDate.charAt(strDate.length() - 1);
  if ((lastChar == 'z') || (lastChar == 'Z')) {
    strDate=strDate.substring(0,strDate.length() - 1);
  }
  return createDate(strDate,diffTime,plusTime);
}

public static Date stringToDate ( String strDate ) throws ParseException { int [ ] diffTime = null ; boolean plusTime = true ; int idxT = strDate . indexOf ( 'T' ) ; if ( idxT == - 1 ) { throw new ParseException ( "Invalid Date Format" , 0 ) ; } int idxDiffUTC = strDate . indexOf ( '-' , idxT ) ; if ( idxDiffUTC == - 1 ) { idxDiffUTC = strDate . indexOf ( '+' , idxT ) ; plusTime = false ; } if ( idxDiffUTC != - 1 ) { diffTime = getDiffTime ( strDate , idxDiffUTC ) ; strDate = strDate . substring ( 0 , idxDiffUTC ) ; } char lastChar = strDate . charAt ( strDate . length ( ) - 1 ) ; if ( ( lastChar == 'z' ) || ( lastChar == 'Z' ) ) { strDate = strDate . substring ( 0 , strDate . length ( ) - 1 ) ; } return createDate ( strDate , diffTime , plusTime ) ; }
returns date that is represented by a string . it uses the following representation of date . yyyy - mm - dd ' t ' hh : mm : ss based on the following definition of " datetime " attribute in xml schema which can be found at http : / / www . w3 . org / tr / xmlschema - 2 / # datetime . a single lexical representation , which is a subset of the lexical representations allowed by [ iso 8601 ] , is allowed for datetime . this lexical representation is the [ iso 8601 ] extended format ccyy - mm - ddthh : mm : ss where " cc " represents the century , " yy " the year , " mm " the month and " dd " the day , preceded by an optional leading " - " sign to indicate a negative number . if the sign is omitted , " + " is assumed . the letter " t " is the date / time separator and " hh " , " mm " , " ss " represent hour , minute and second respectively . additional digits can be used to increase the precision of fractional seconds if desired i . e the format ss . ss . . . with any number of digits after the decimal point is supported . the fractional seconds part is optional ; other parts of the lexical form are not optional . to accommodate year values greater than 9999 additional digits can be added to the left of this representation . leading zeros are required if the year value would otherwise have fewer than four digits ; otherwise they are forbidden . the year 0000 is prohibited . the ccyy field must have at least four digits , the mm , dd , ss , hh , mm and ss fields exactly two digits each ( not counting fractional seconds ) ; leading zeroes must be used if the field would otherwise have too few digits . this representation may be immediately followed by a " z " to indicate coordinated universal time ( utc ) or , to indicate the time zone , i . e . the difference between the local time and coordinated universal time , immediately followed by a sign , + or - , followed by the difference from utc represented as hh : mm ( note : the minutes part is required ) . see iso 8601 date and time formats ( ' d ) for details about legal values in the various fields . if the time zone is included , both hours and minutes must be present . for example , to indicate 1 : 20 pm on may the 31st , 1999 for eastern standard time which is 5 hours behind coordinated universal time ( utc ) , one would write : 1999 - 05 - 31t13 : 20 : 00 - 05 : 00 .
