Java Utililty Methods Milliseconds

List of utility methods to do Milliseconds

Description

The list of methods to do Milliseconds are organized into topic(s).

Method

longtimeSinceMillis(long timestart)
Time elapsed since a start time.
return (timeSince(timestart) / 1000000);
longtimespanToMillis(String timeString)
timespan To Millis
Pattern pattern = Pattern.compile("(-?\\d+\\.?\\d*)([\\w]{0,1})", Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(timeString);
if (matcher.matches()) {
    double baseMillis = Double.parseDouble(matcher.group(1));
    String unit = matcher.group(2).toLowerCase();
    if (unit.equals("d") || unit.length() == 0) {
        return (long) (baseMillis * 1000 * 3600 * 24);
    } else if (unit.equals("h")) {
...
StringtimestampToString(long lastModifiedMillis)
timestamp To String
Date date = new Date(lastModifiedMillis);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
return format.format(date);
longtimeToMilliseconds(Object unit, long interval)
time To Milliseconds
switch (unit.toString()) {
case "SECONDS":
    return interval * 1000L;
case "MINUTES":
    return interval * 1000L * 60L;
case "HOURS":
    return interval * 1000L * 60L * 60L;
case "DAYS":
...
StringtimeToString(long timeMillis)
Returns a String representation of the time.
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
return dateFormat.format(new Date(timeMillis));
StringtimeToTag(long milliSeconds)
time To Tag
SimpleDateFormat sdf = new SimpleDateFormat("mm:ss.SS");
Date d = new Date(milliSeconds);
String text = sdf.format(d);
text = text.substring(0, text.length() - 1);
return text;
longtoMillis(String ts)
convert timestamp to millis
Date dts = toDate(ts);
return dts.getTime();
StringtoSpacelessDateString(long millisSinceEpoch)
to Spaceless Date String
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-HHmmss", Locale.US);
Date t = new Date(millisSinceEpoch);
return sdf.format(t);
StringToSting(Long milliSecond)
To Sting
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return sdf.format(milliSecond);
StringtoTime(long milli)
to Time
Calendar date = Calendar.getInstance();
date.setTimeInMillis(milli);
DateFormat format = new SimpleDateFormat("HH:mm:ss");
return format.format(date.getTime());