List of utility methods to do Hour Calculate
boolean | isValidTime(int hour, int minute, boolean ampm) Tests if the inputs are valid time. if (minute < 0 || minute > 59) return false; if (ampm && (hour < 1 || hour > 12)) return false; else if (hour < 0 || hour > 23) return false; else return true; ... |
long | parseDate(String date, String hours) parse Date return parseDate(date + " " + hours); |
Date | plusHour(int hour) plus Hour Calendar cal = Calendar.getInstance();
cal.add(Calendar.HOUR, hour);
return cal.getTime();
|
String | plusHour(String dateStr, int hour) plus Hour SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmssSSS"); Date date = formatter.parse(dateStr); Calendar cal = Calendar.getInstance(); cal.setTime(date); cal.add(Calendar.HOUR, hour); String resultStr = formatter.format(cal.getTime()); return resultStr; |
Date | plusHours(Date date, int hours) plus Hours if (date == null) date = getToday(); return changeHours(date, hours); |
String | plusOrMinusHours(Date dateTime, long count) plus Or Minus Hours try { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); dateTime.setTime(dateTime.getTime() + count * 3600000); return sdf.format(dateTime); } catch (Exception e) { e.printStackTrace(); return ""; |
Date | setHours(Date date, int amount) Sets the hours field to a date returning a new object. return set(date, Calendar.HOUR_OF_DAY, amount);
|
String | toStringHour(int hours, int minutes, int seconds, int millis) to String Hour return String.format("%02d:%02d:%02d.%03d", hours, minutes, seconds, millis); |
String | toTime(int hours, int minutes, int seconds) to Time DecimalFormat df = new DecimalFormat("00"); return df.format(hours) + ":" + df.format(minutes) + ":" + df.format(seconds); |
Date | trimToHour(Date date) trim To Hour Calendar c = new GregorianCalendar(); c.setTime(date); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); return c.getTime(); |