DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=29794>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=29794

Add convenience format(long) methods to FastDateFormat

           Summary: Add convenience format(long) methods to FastDateFormat
           Product: Commons
           Version: 2.0 Final
          Platform: All
        OS/Version: Other
            Status: NEW
          Severity: Enhancement
          Priority: Other
         Component: Lang
        AssignedTo: [EMAIL PROTECTED]
        ReportedBy: [EMAIL PROTECTED]


it is sometimes necessary to format based on a long timeInMillis [for instance 
either directly from System.currentTimeInMillis or from a File.lastModified()].

I have an extension of FastDateFormat that adds the following methods to 
support this:

        /**
         * <p>Formats a <code>long</code> timeInMillis. Useful if you don't 
want 
         * to create a Date or don't have a Calendar intance</p>
         * 
         * @param date the new time in UTC milliseconds from the epoch 
(1/1/1970).
         * @return the formatted string
         */
        public String format(long timeInMillis) {
                return format(timeInMillis, new StringBuffer
(mMaxLengthEstimate)).toString();
        }

        /**
         * <p>Formats a <code>long</code> timeInMillis. Useful if you don't 
want 
         * to create a Date or don't have a Calendar intance</p>
         * 
         * @param date the new time in UTC milliseconds from the epoch 
(1/1/1970).
         * @return the formatted string
         */
        public StringBuffer format(long timeInMillis, StringBuffer buf) {
                class UtilGregorianCalendar extends GregorianCalendar {
                        UtilGregorianCalendar(TimeZone timeZone) {
                                super(timeZone);
                        }
                        
                        public void setTimeInMillis(long timeInMillis) {
                                super.setTimeInMillis(timeInMillis);
                        }
                }

                UtilGregorianCalendar c = new UtilGregorianCalendar(mTimeZone);
                c.setTimeInMillis(timeInMillis);
                return applyRules(c, buf);
        }

and a minor change to format(Object, StringBuffer, FieldPosition:

                else if (obj instanceof Long) {
                        return format(((Long) obj).longValue(), toAppendTo);
                }

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to