List of utility methods to do Millisecond to Hour
String | getHoursFromMillis(long ms) get Hours From Millis double numSeconds = ((ms) / 1000d); return String.valueOf(numSeconds / 3600); |
long | getHoursIntoMilliseconds(int nbHours) get Hours Into Milliseconds return ((long) nbHours) * 3600 * 1000; |
int | getHourSpareFromMilliSecond(int milliSecond) get Hour Spare From Milli Second return (milliSecond) % (60 * 60 * 1000);
|
long | getMilliSecondByHourAndMins(int hour, int min) get Milli Second By Hour And Mins return hour * 60 * 60 * 1000 + min * 60 * 1000;
|
long | getMillisFromHours(String hours) Edited this method by adding a nested try catch block that will parse input when the use enters the time in ##h##m format, it will also handle any format in ##H##M, ##h, ##H, ##m, ##M. if (hours == null || hours.length() == 0) { return 0; try { double numHours = Double.parseDouble(hours); if (numHours < 0.0) { return 0; double millisDouble = (numHours * 3600 * 1000); return (long) millisDouble; } catch (NumberFormatException e) { String hour = new String(); String minute = new String(); String temp = new String(); for (int i = 0; i < hours.length(); i++) { if (hours.charAt(i) == 'h' || hours.charAt(i) == 'H') { hour = temp; temp = ""; } else if (hours.charAt(i) == 'm' || hours.charAt(i) == 'M') { minute = temp; temp = ""; } else if (hours.charAt(i) < '0' || hours.charAt(i) > '9') { return 0; } else { temp += hours.charAt(i); Double numHours = 0.0; Double numMinutes = 0.0; if (hour.length() != 0) { numHours = Double.parseDouble(hour); } else { hour = "0"; if (minute.length() != 0) { numMinutes = Double.parseDouble(minute); numMinutes = numMinutes / 60.0; numHours += numMinutes; double millisDouble = (numHours * 3600 * 1000); return (long) millisDouble; |
long | getMillisFromHours(String hours) get Millis From Hours try { double numHours = Double.parseDouble(hours); double millisDouble = (numHours * 3600 * 1000); return (long) millisDouble; } catch (NumberFormatException e) { return 0; |
long | milliseconds(long p_days, long p_hours, long p_minutes, long p_hoursPerBusinessDay) Convert the given number of days, hours, and minutes into the corresponding number of milliseconds. long seconds = p_days * p_hoursPerBusinessDay * MINUTES_PER_HOUR * SECONDS_PER_MINUTE; seconds += p_hours * MINUTES_PER_HOUR * SECONDS_PER_MINUTE; seconds += p_minutes * SECONDS_PER_MINUTE; return seconds * MILLIS_PER_SECOND; |
String | millisecondsToHours(long ms) Convert from milliseconds to hours. int hours = (int) (ms / (MS_PER_S * S_PER_M * M_PER_H)); return hours + "h"; |
Double | millisecondToHour(Long millisecond) millisecond To Hour return (millisecond) / (3600 * 1000 * 1d);
|
double | millisToHours(double millis) _more_ return millis / 1000 / 60 / 60;
|