private void addTimeToReport ( ) { // record the time SimpleDateFormat stf = new SimpleDateFormat ( "HH:mm:ss" ) ; String timeNow = stf . format ( new Date ( ) ) ; long totalTime = ( new Date ( ) ) . getTime ( ) - startTime ; long time = totalTime / 1000 ; StringBuilder seconds = new StringBuilder ( Integer . toString ( ( int ) ( time % 60 ) ) ) ; StringBuilder minutes = new StringBuilder ( Integer . toString ( ( int ) ( ( time % 3600 ) / 60 ) ) ) ; StringBuilder hours = new StringBuilder ( Integer . toString ( ( int ) ( time / 3600 ) ) ) ; for ( int i = 0 ; i < 2 ; i ++ ) { if ( seconds . length ( ) < 2 ) { seconds . insert ( 0 , "0" ) ; } if ( minutes . length ( ) < 2 ) { minutes . insert ( 0 , "0" ) ; } if ( hours . length ( ) < 2 ) { hours . insert ( 0 , "0" ) ; } } replaceInFile ( "RUNTIME" , hours + ":" + minutes + ":" + seconds ) ; replaceInFile ( "TIMEFINISHED" , timeNow ) ; }
Updates the output file with timing information including run time and finish time