Format given Date object into INTERNALDATE string
/*
* SimpleDateFormat objects aren't thread safe, so rather
* than create a separate such object for each request,
* we create one object and synchronize its use here
* so that only one thread is using it at a time. This
* trades off some potential concurrency for speed in the
* common case.
*
* This method is only used when formatting the date in a
* message that's being appended to a folder.
*/
StringBuffer sb = new StringBuffer();
synchronized (df) {
df.format(d, sb, new FieldPosition(0));
}
// compute timezone offset string
// XXX - Yes, I know this is deprecated
int rawOffsetInMins = -d.getTimezoneOffset();
/*
* XXX - in JavaMail 1.4 / J2SE 1.4, possibly replace above with:
*
TimeZone tz = TimeZone.getDefault();
int offset = tz.getOffset(d); // get offset from GMT
int rawOffsetInMins = offset / 60 / 1000; // offset from GMT in mins
*/
if (rawOffsetInMins < 0) {
sb.append('-");
rawOffsetInMins = (-rawOffsetInMins);
} else
sb.append('+");
int offsetInHrs = rawOffsetInMins / 60;
int offsetInMins = rawOffsetInMins % 60;
sb.append(Character.forDigit((offsetInHrs/10), 10));
sb.append(Character.forDigit((offsetInHrs%10), 10));
sb.append(Character.forDigit((offsetInMins/10), 10));
sb.append(Character.forDigit((offsetInMins%10), 10));
return sb.toString();