Java Utililty Methods Time Readable Format

List of utility methods to do Time Readable Format

  1. HOME
  2. Java
  3. T
  4. Time Readable Format

Description

The list of methods to do Time Readable Format are organized into topic(s).

Method

java.util.Date getMaxTimeByStringDate(String date)
get Max Time By String Date
try {
 String maxTime = date + " 23:59:59";
 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 return sdf.parse(maxTime);
} catch (Exception e) {
 return null;
String humanTime(long ms)
human Time
StringBuffer text = new StringBuffer("");
if (ms > DAY) {
 text.append(ms / DAY).append(" d ");
 ms %= DAY;
if (ms > HOUR) {
 text.append(ms / HOUR).append(" h ");
 ms %= HOUR;
...
String humanTime(long seconds)
human Time
long diff[] = new long[] { 0, 0, 0, 0 };
diff[3] = (seconds >= 60 ? seconds % 60 : seconds);
diff[2] = (seconds = (seconds / 60)) >= 60 ? seconds % 60 : seconds;
diff[1] = (seconds = (seconds / 60)) >= 24 ? seconds % 24 : seconds;
diff[0] = (seconds = (seconds / 24));
String text = String.format(
 "%d days %02d:%02d:%02d", diff[0],
 diff[1],
...
String humanTime(long start, long end)
Construct a human readable string of a duration
if (start != -1L) {
 final long finalTime = (end - start) / 1000L;
 final long MINUTE = 60L;
 final long HOUR = 60 * MINUTE;
 final long DAY = 24 * HOUR;
 final long MONTH = 30 * DAY;
 final long YEAR = 365 * DAY;
 if (finalTime >= YEAR) {
...
String toHumanable(long time_millsecod)
to Humanable
long second = time_millsecod / 1000;
if (second < 60) {
 return second + "s";
} else if (second < 60 * 60) {
 return second / (60) + "min";
} else if (second < 60 * 60 * 24) {
 return second / (60 * 60) + "hour";
} else {
...
String toTime(int duration)
to Time
double asMinutes = ((double) duration) / 60.0;
int minutes = (int) Math.floor(asMinutes);
int seconds = duration - (minutes * 60);
return minutes + ":" + ((seconds + "").length() < 2 ? "0" + seconds : seconds);
String toTime(long ms)
Turn the input long into a string on the form (D:)HH:MM:SS, where the day-part is only added if the number of days is greater than or equal to 1, i.e.
long total = ms / 1000;
long secs = total % 60;
long mins = total % 3600 / 60;
long hours = total / 3600 % 24;
long days = total / 3600 / 24;
String time = (days > 0 ? days + ":" : "") + (hours < 10 ? "0" + hours : hours) + ":"
 + (mins < 10 ? "0" + mins : mins) + ":" + (secs < 10 ? "0" + secs : secs);
return time;
...
String toTime(long nanos)
to Time
if (nanos < 1_000_000L) {
 return nanos + " ns";
long l;
StringBuilder builder = new StringBuilder();
if (nanos >= 60_000_000_000L) 
 l = nanos / 60_000_000_000L;
...
String toTime(long time)
to Time
return time / 3600 + ":" + time % 3600 / 60 + ":" + time % 60;
String toTime2(int value, int nanos, int meta)
to Time
final int h = (value >> 12) & 0x3FF;
final int m = (value >> 6) & 0x3F;
final int s = (value >> 0) & 0x3F;
String format = "%02d:%02d:%02d";
return String.format(format, h, m, s) + microSecondToStr(nanos, meta);


AltStyle によって変換されたページ (->オリジナル) /