code: public static Date getDateFromString(String date) throws ParseException {
          DateFormat formatter = new SimpleDateFormat(DATE_yyyyMMddTHHmmssSSSZ);
  
          if (date.charAt(date.length() - 3) == ':' && !date.endsWith("Z")) {
              date = date.substring(0, date.lastIndexOf(':')) + date.substring(date.lastIndexOf(':') + 1, date.length());
              if (!date.contains(".")) {
                  formatter = new SimpleDateFormat(DATE_yyyMMddTHHmmssZ);
              }
  
          } else if (date.charAt(date.length() - 3) != ':' && !date.endsWith("Z")) {
              if (!date.contains(".")) {
                  formatter = new SimpleDateFormat(DATE_yyyMMddTHHmmssZ);
              }
  
          } else if (date.endsWith("Z") && date.contains(".")) {
              formatter = new SimpleDateFormat(DATE_yyyyMMddTHHmmssSSSZone);
          } else if (date.endsWith("Z") && !date.contains(".")) {
              formatter = new SimpleDateFormat(DATE_yyyMMddTHHmmssZone);
          }
          return formatter.parse(date);
      }
docs: Note: The below method uses date formats that are supported by Java SE 1.6 since we still
  need to support it. Moving forward when we port to Java SE 1.7 please update the code and
  use more generic date formats to make the code more robust.
  Java SE 1.6: http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html
  Java SE 1.7: http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html