Created
October 30, 2019 23:10
-
-
Save sontqq/cb4bb2ad415c78b6c2302fe0a49a5396 to your computer and use it in GitHub Desktop.
TimeElapsedUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package sample; | |
import java.text.DateFormat; | |
import java.text.SimpleDateFormat; | |
import java.util.Date; | |
import java.util.TimeZone; | |
public class TimeElapsedUtil { | |
public long startTime; | |
public long now; | |
public void setStartTime(long startTime) { | |
this.startTime = startTime; | |
} | |
public TimeElapsedUtil() { | |
this.startTime = System.currentTimeMillis(); | |
this.now = System.currentTimeMillis(); | |
} | |
public TimeElapsedUtil(long startTime) { | |
this.startTime = startTime; | |
this.now = System.currentTimeMillis(); | |
} | |
public TimeElapsedUtil(long startTime, long now) { | |
this.startTime = startTime; | |
this.now = now; | |
} | |
public String getElapsed() { | |
this.now = System.currentTimeMillis(); | |
return convertLongToHRString(this.now - this.startTime); | |
} | |
private String convertLongToHRString(long val) { | |
Date date = new Date(val); | |
DateFormat formatter = new SimpleDateFormat("HH:mm:ss.SSS"); | |
formatter.setTimeZone(TimeZone.getTimeZone("UTC")); | |
return formatter.format(date); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment