List of utility methods to do Long Number to Time
String | stringTime(long time) PURPOSE: stringTime DecimalFormat twoDigitIntFormat = new DecimalFormat("00"); DecimalFormat threeDigitIntFormat = new DecimalFormat("000"); int hrs = (int) (time / (1000 * 60 * 60)); int mins = (int) ((time % (1000 * 60 * 60)) / (1000 * 60)); int sec = (int) (((time % (1000 * 60 * 60)) % (1000 * 60)) / 1000); int millis = (int) (time % 1000); return String.format("%s:%s:%s.%s", twoDigitIntFormat.format(hrs), twoDigitIntFormat.format(mins), twoDigitIntFormat.format(sec), threeDigitIntFormat.format(millis)); ... |
long | stringTolong(String time) string Tolong SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date dt2; long lTime = 0; try { if (time != null && !time.equals("")) { dt2 = sdf.parse(time); lTime = dt2.getTime(); } else { ... |
String | time2Date(Long time) time Date SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); if (time != null) { String date = format.format(time); return date; return null; |
String | time2DATETIME(long time) time DATETIME SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date d = new Date(time); return "\"" + fmt.format(d) + "\""; |
long | toLong(String time) to Long try { return completeToLong(time); } catch (ParseException e) { try { return completeWithoutZoneToLong(time); } catch (ParseException e) { try { return minSecondToLong(time); } catch (ParseException e) { try { return minSecondWithoutZoneToLong(time); } catch (ParseException e) { try { return minMinToLong(time); } catch (ParseException e) { try { return minMinWithoutZoneToLong(time); } catch (ParseException e) { try { return minHourToLong(time); } catch (ParseException e) { try { return minHourWithoutZoneToLong(time); } catch (ParseException e) { try { return minDayToLong(time); } catch (ParseException e) { try { return minDayWithoutZoneToLong(time); } catch (ParseException e) { throw new IllegalArgumentException("can't parse this time format."); |
String | toLongString(long ms) to Long String return format(ms, "yyyy-MM-dd HH:mm:ss.SSS"); |
String | toTextTime(long time) to Text Time long h = time / 3600; long m = time % 3600 / 60; long s = time % 60; StringBuilder sb = new StringBuilder(); if (h > 0) { sb.append(h); sb.append(" Hour"); if (h > 1) { ... |
String | transformDateTime(long t) transform Date Time Date date = new Date(t); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); return dateFormat.format(date); |