1 package org.webdocwf.util.loader; 2 3 11 12 30 import java.text.SimpleDateFormat ; 31 import java.text.DateFormat ; 32 import java.util.Date ; 33 34 40 public class TimeWatch { 41 42 private long startTime = 0; 43 private long startJobTime = 0; 44 45 48 public TimeWatch() { 49 this.startJobTime=0; 50 this.startTime=System.currentTimeMillis(); 51 } 52 53 54 58 public String getTotalTime() { 59 long currentTime = System.currentTimeMillis(); 60 long difference = currentTime-this.startTime; 61 62 if(difference>60000){ 63 long minutes = difference/60000; 64 long remainder = difference%60000; 65 return new String ((new Long (minutes)).toString()+" minutes "+ 66 (new Long (remainder/1000)).toString()+","+(new Long (remainder%1000)).toString()+" seconds"); 67 } 68 else if(currentTime>1000) 69 return new String ((new Long (difference/1000)).toString()+","+(new Long (difference%1000)).toString()+" seconds"); 70 else 71 return new String ((new Long (difference)).toString() +" miliseconds"); } 72 73 76 public void setStartJobTime() { 77 this.startJobTime = System.currentTimeMillis(); 78 } 79 80 83 public void setStartTime() { 84 this.startTime = System.currentTimeMillis(); 85 } 86 90 public String getJobTime() { 91 long currentTime = System.currentTimeMillis(); 93 long difference = currentTime-this.startJobTime; 94 if(difference>60000){ 95 long minutes = difference/60000; 96 long remainder = difference%60000; 97 return new String ((new Long (minutes)).toString()+" minutes "+ 98 (new Long (remainder/1000)).toString()+","+(new Long (remainder%1000)).toString()+" seconds"); 99 } 100 else if(currentTime>1000) 101 return new String ((new Long (difference/1000)).toString()+","+(new Long (difference%1000)).toString()+" seconds"); 102 else 103 return new String ((new Long (difference)).toString() +" miliseconds"); 104 } 105 106 109 public void reset() { 110 this.startJobTime=0; 111 } 112 113 } | Popular Tags |