avalon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bian Tan" <b...@modulant.com>
Subject RE: Date Formatter for LogKitManagement
Date Wed, 12 Dec 2001 23:38:38 GMT
Good Catch! Chad Stansbury!

Pity, looks like Peter Donald already checked in the original
Perhaps we can get the more optimal code checked in too?
Is there an upcoming release of LogKit?


-----Original Message-----
From: Chad Stansbury [mailto:stansburyc@earthlink.net]
Sent: Wednesday, December 12, 2001 3:09 PM

For the speed freaks like myself, here's another optimization to the Date
formatter code.  You can improve upon the speed by removing the Date
instantiation (which in the quoted code will be invoked for each line being
logged), and replacing w/ a setTime call...  The new code would be:

import java.util.Date;
import java.text.SimpleDateFormat;

SimpleDateFormat m_dateFormatter = null;
Date m_date = new Date();

protected String getTime( final long time, final String format )
{
    if ( format == null ){
        return Long.toString( time );
    }

    if (m_dateFormatter == null) {
        m_dateFormatter = new SimpleDateFormat( format );
    }

    m_date.setTime( System.currentTimeMillis() );
    return( m_dateformatter.format( m_date ) );
}

Chad Stansbury


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message