import java.util.Calendar;
class Main {
/**
* Generate a ISO 8601 date
*
* @param date
* a Date instance
* @return a string representing the date in the ISO 8601 format
*/
public static String getIsoDate(Calendar calendar) {
StringBuffer buffer = new StringBuffer();
buffer.append(calendar.get(Calendar.YEAR));
buffer.append("-");
buffer.append(twoDigit(calendar.get(Calendar.MONTH) + 1));
buffer.append("-");
buffer.append(twoDigit(calendar.get(Calendar.DAY_OF_MONTH)));
buffer.append("T");
buffer.append(twoDigit(calendar.get(Calendar.HOUR_OF_DAY)));
buffer.append(":");
buffer.append(twoDigit(calendar.get(Calendar.MINUTE)));
buffer.append(":");
buffer.append(twoDigit(calendar.get(Calendar.SECOND)));
buffer.append(".");
buffer.append(twoDigit(calendar.get(Calendar.MILLISECOND) / 10));
// buffer.append("Z");
int offset = calendar.get(Calendar.ZONE_OFFSET) / (1000 * 60 * 60);
if (offset > 0) {
buffer.append("+");
} else {
buffer.append("-");
}
buffer.append(twoDigit(offset));
buffer.append(":00");
return buffer.toString();
}
public static String twoDigit(int i) {
if (i >= 0 && i < 10) {
return "0" + String.valueOf(i);
}
return String.valueOf(i);
}
}