Code example for Calendar

Methods: getgetTimeZone

0
     * @param needSpace 
     *            <tt>true</tt> if a space character should be inserted before 
     *            any data 
     */ 
    private static final void appendTimeString(StringBuffer buf, Calendar cal, boolean needSpace) {
        final int hour = cal.get(Calendar.HOUR_OF_DAY);
        final int minute = cal.get(Calendar.MINUTE);
        final int second = cal.get(Calendar.SECOND);
        final int milli = cal.get(Calendar.MILLISECOND);
 
        if (hour != 0 || minute != 0 || second != 0 || milli != 0) {
            if (needSpace) {
                buf.append(' ');
            } 
            if (hour < 10) {
                buf.append(' ');
            } 
            buf.append(hour);
 
            if (minute < 10) {
                buf.append(":0");
            } else { 
                buf.append(':');
            } 
            buf.append(minute);
 
            if (second != 0 || milli != 0) {
                if (second < 10) {
                    buf.append(":0");
                } else { 
                    buf.append(':');
                } 
                buf.append(second);
 
                if (milli != 0) {
                    if (milli < 10) {
                        buf.append(".00");
                    } else if (milli < 100) {
                        buf.append(".0");
                    } else { 
                        buf.append('.');
                    } 
                    buf.append(milli);
                } 
            } 
        } 
 
        TimeZone tz = cal.getTimeZone();
        if (tz.getRawOffset() == 0) {
            buf.append(" GMT");
        } else { 
            buf.append(' ');