public static String getIsoDate(Calendar origCalendar) {
    if (origCalendar == null) return null;
    // Calendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
    // calendar.setTime(date);
    StringBuffer buffer = new StringBuffer();
    // doing a calendar.get() causes *all* fields to be set!
    // To avoid side effects, we clone the supplied calendar
    // So that we only print truly specified fields, we check which ones are set before get()ing any
    Calendar calendar = (Calendar)origCalendar.clone();
    calendar.setLenient(true);
    boolean isYearSet = calendar.isSet(Calendar.YEAR);
    boolean isMonthSet = calendar.isSet(Calendar.MONTH);
    boolean isDayOfMonthSet = calendar.isSet(Calendar.DAY_OF_MONTH);
    boolean isHourOfDaySet = calendar.isSet(Calendar.HOUR_OF_DAY);
    boolean isMinuteSet = calendar.isSet(Calendar.MINUTE);
    boolean isSecondSet = calendar.isSet(Calendar.SECOND);
    boolean isMillisecondSet = calendar.isSet(Calendar.MILLISECOND);
    if (!isYearSet) return buffer.toString();
    buffer.append(calendar.get(Calendar.YEAR));
    if (!isMonthSet) return buffer.toString();
    buffer.append("-");
    buffer.append(twoDigit(calendar.get(Calendar.MONTH) + 1));
    if (!isDayOfMonthSet) return buffer.toString();
    buffer.append("-");
    buffer.append(twoDigit(calendar.get(Calendar.DAY_OF_MONTH)));
    if (!isHourOfDaySet) return buffer.toString();
    buffer.append("T");
    buffer.append(twoDigit(calendar.get(Calendar.HOUR_OF_DAY)));
    if (!isMinuteSet) return buffer.toString();
    buffer.append(":");
    buffer.append(twoDigit(calendar.get(Calendar.MINUTE)));
    if (!isSecondSet) return buffer.toString();
    buffer.append(":");
    buffer.append(twoDigit(calendar.get(Calendar.SECOND)));
    if (!isMillisecondSet) return buffer.toString();
    buffer.append(".");
    buffer.append(twoDigit(calendar.get(Calendar.MILLISECOND) / 10));
    buffer.append("Z");
    return buffer.toString();
  }