Ejemplo n.º 1
0
  // parses a datetime string that adhears to the given pattern and returns a java.util.Date object
  public static java.util.Calendar parse(String input, String pattern)
      throws IllegalArgumentException {
    if (pattern == null) pattern = DEFAULT_DATETIME_PATTERN;

    java.util.Calendar output = null;

    if (input != null) {
      if (pattern.equals("datetime")) {
        output = javax.xml.bind.DatatypeConverter.parseDateTime(input);
      } else if (pattern.equals("date")) {
        output = javax.xml.bind.DatatypeConverter.parseDate(input);
      } else if (pattern.equals("time")) {
        output = javax.xml.bind.DatatypeConverter.parseTime(input);
      } else if (pattern.equals("milliseconds")) {
        output = java.util.Calendar.getInstance();
        output.setTimeInMillis(Long.parseLong(input));
      } else {
        java.text.DateFormat formatter = new java.text.SimpleDateFormat(pattern);
        formatter.setLenient(false);
        output = java.util.Calendar.getInstance();
        try {
          output.setTime(formatter.parse(input));
        } catch (java.text.ParseException ex) {
          throw new IllegalArgumentException(tundra.exception.message(ex));
        }
      }
    }

    return output;
  }
Ejemplo n.º 2
0
 @Override
 public Calendar unmarshal(String v) throws Exception {
   return ETime.asTime(DatatypeConverter.parseTime(v));
 }