Skip to content

Commit

Permalink
[*] update getFormattedTime to follow hh:mm:ss format strictly, fixes…
Browse files Browse the repository at this point in the history
… issue #6
  • Loading branch information
nisrulz committed May 11, 2016
1 parent 7e8da7f commit 6e4c8ac
Showing 1 changed file with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.Calendar;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
Expand Down Expand Up @@ -1325,15 +1324,18 @@ public long getTime() {
}

/**
* Gets formated time.
* Gets formatted time.
*
* @return the formated time
* @return the formatted time
*/
public String getFormatedTime() {
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(System.currentTimeMillis());
return cal.get(Calendar.HOUR_OF_DAY) + ":" + cal.get(Calendar.MINUTE) + ":" + cal.get(
Calendar.SECOND);

long millis = System.currentTimeMillis();
int sec = (int) (millis / 1000) % 60;
int min = (int) ((millis / (1000 * 60)) % 60);
int hr = (int) ((millis / (1000 * 60 * 60)) % 24);

return String.format("%02d:%02d:%02d", hr, min, sec);
}

/**
Expand Down

0 comments on commit 6e4c8ac

Please sign in to comment.