List of utility methods to do Time Different
double | calculateExecutionTimeDiff(String startDate, String endDate) calculate Execution Time Diff Date start = null; Date end = null; startDate = startDate.replace(" ", " "); endDate = endDate.replace(" ", " "); DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US); try { start = formatter.parse(startDate); end = formatter.parse(endDate); ... |
Date | createDate(String strDate, int[] timeDiff, boolean plusDiff) Returns a date with a string of yyyy-MM-ssThh:mm:ss or yyyy-MM-ssThh:mm. try { int year = Integer.parseInt(strDate.substring(0, 4)); if (strDate.charAt(4) != '-') { throw new ParseException("Invalid Date Format", 0); int month = Integer.parseInt(strDate.substring(5, 7)) - 1; if (strDate.charAt(7) != '-') { throw new ParseException("Invalid Date Format", 0); ... |
int | diffTime(String sTime, String fTime, String Dateformat1) diff Time SimpleDateFormat myFormatter = new SimpleDateFormat(Dateformat1); java.util.Date stime = myFormatter.parse(sTime); java.util.Date ftime = myFormatter.parse(fTime); int second = (int) ((ftime.getTime() - stime.getTime()) / 1000); return second; |
Date | getDiffDateTime(int diff) get Diff Date Time Calendar c = Calendar.getInstance(); c.setTime(new Date()); c.add(Calendar.DATE, diff); return c.getTime(); |
long | getDifferent(final Date timeFrom, final Date timeTo) Gets the different. final DateFormat format = new SimpleDateFormat("HH:mm:ss"); final Date date = format.parse(timeFrom.toString()); final Date date2 = format.parse(timeTo.toString()); final long difference = (date2.getTime() - date.getTime()) / 1000 / 60; return difference; |
long | getDiffTime(Date beforeTime, Date afterTime) get Diff Time try { String beforeTimeStr = FORMAT_HMS.format(beforeTime); String afterTimeStr = FORMAT_HMS.format(afterTime); Date bTime = parseTime(beforeTimeStr); Date aTime = parseTime(afterTimeStr); long diff = aTime.getTime() - bTime.getTime(); return diff; } catch (Exception e) { ... |
String | getDiffTime(long startTime) get Diff Time return NUMBER_FORMAT.format((System.nanoTime() - startTime) * 0.000001) + " ms"; |
int[] | getDiffTime(String strDate, int idx) Returns the difference portion of a date string. String strDiff = strDate.substring(idx + 1, strDate.length() - 1); int[] diffArray = new int[2]; int colonIdx = strDiff.indexOf(':'); if (colonIdx == -1) { throw new ParseException("Invalid Date Format", 0); try { diffArray[0] = Integer.parseInt(strDiff.substring(0, colonIdx)); ... |
String | getFormattedTimeWithDiff(DateFormat dateFormat, long finishTime, long startTime) Formats time in ms and appends difference (finishTime - startTime) as returned by formatTimeDiff(). StringBuffer buf = new StringBuffer(); if (0 != finishTime) { buf.append(dateFormat.format(new Date(finishTime))); if (0 != startTime) { buf.append(" (" + formatTimeDiff(finishTime, startTime) + ")"); return buf.toString(); ... |
long | getTimeDiff(String start, String end, String format, int timeDiff) get time diff between start and end using format try { SimpleDateFormat dateFormat = new SimpleDateFormat(format); Date d1 = dateFormat.parse(start); Date d2 = dateFormat.parse(end); return ((d1.getTime() - d2.getTime()) / timeDiff); } catch (ParseException e) { throw new IOException("can't parse date, start:" + start + " end:" + end); |