Java Utililty Methods Long Number to Time

List of utility methods to do Long Number to Time

Description

The list of methods to do Long Number to Time are organized into topic(s).

Method

StringstringTime(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));
...
longstringTolong(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 {
...
Stringtime2Date(Long time)
time Date
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
if (time != null) {
    String date = format.format(time);
    return date;
return null;
Stringtime2DATETIME(long time)
time DATETIME
SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date d = new Date(time);
return "\"" + fmt.format(d) + "\"";
longtoLong(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.");
StringtoLongString(long ms)
to Long String
return format(ms, "yyyy-MM-dd HH:mm:ss.SSS");
StringtoTextTime(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) {
...
StringtransformDateTime(long t)
transform Date Time
Date date = new Date(t);
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return dateFormat.format(date);