Skip to content

Instantly share code, notes, and snippets.

@dotrinh-DM
Created January 22, 2024 01:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dotrinh-DM/bb1e67e4fedb30a8e7ce324cd8f7c876 to your computer and use it in GitHub Desktop.
Save dotrinh-DM/bb1e67e4fedb30a8e7ce324cd8f7c876 to your computer and use it in GitHub Desktop.
calculate duration of transaction Java
/*
* Created by dotrinh on 7/21/20 12:28 PM
*/
package jp.co.zoom.handyrecorder.tool;
/**
* calculate duration of transaction
*
* Usage:
* Start:
* TransactionTime transactionTime = new TransactionTime(System.currentTimeMillis());
*
* End:
* transactionTime.setEnd(System.currentTimeMillis());
*
* Check dusration:
* transactionTime.getDuration()
*/
public class TransactionTime {
public long start;
public long end;
public TransactionTime() {
}
public TransactionTime(long start) {
this.start = start;
}
public void setEnd(long end) {
this.end = end;
}
/**
* Get duration of transaction in millisecond
* @return
*/
public long getDuration() {
if (this.start > 0 && this.end > 0) {
return this.end - this.start;
} else {
return 0;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment