Beispiel #1
0
 /**
  * @param dt
  * @return
  */
 public static String printDate(Date dt) {
   if (dt != null) {
     Calendar cal = new GregorianCalendar();
     cal.setTime(dt);
     return DatatypeConverter.printDate(cal);
   }
   return null;
 }
Beispiel #2
0
  // returns the given datetime formatted as a string adhering to the given pattern
  public static String emit(java.util.Calendar input, String pattern) {
    if (pattern == null) pattern = DEFAULT_DATETIME_PATTERN;
    String output = null;

    if (input != null) {
      if (pattern.equals("datetime")) {
        output = javax.xml.bind.DatatypeConverter.printDateTime(input);
      } else if (pattern.equals("date")) {
        output = javax.xml.bind.DatatypeConverter.printDate(input);
      } else if (pattern.equals("time")) {
        output = javax.xml.bind.DatatypeConverter.printTime(input);
      } else if (pattern.equals("milliseconds")) {
        output = "" + input.getTimeInMillis();
      } else {
        java.text.DateFormat formatter = new java.text.SimpleDateFormat(pattern);
        formatter.setLenient(false);
        output = formatter.format(input.getTime());
      }
    }

    return output;
  }