Java Millisecond Format formatTimeWithMillis(double time)

Here you can find the source of formatTimeWithMillis(double time)

Description

format Time With Millis

License

Open Source License

Declaration

public static String formatTimeWithMillis(double time) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.text.DecimalFormat;

public class Main {
    public static String formatTimeWithMillis(double time) {
        int hours = (int) time / 3600;
        int minutes = (int) (time - (hours * 3600)) / 60;
        int seconds = (int) time - (hours * 3600) - (minutes * 60);
        double millis = time - (hours * 3600) - (minutes * 60) - seconds;
        String hoursString = hours + "";
        String minutesString = minutes + "";
        String secondsString = seconds + "";
        String millisString = new DecimalFormat(".000").format(millis);
        millisString = millisString.substring(1);
        while (minutesString.length() < 2) {
            minutesString = "0" + minutesString;
        }/*  w w w  .  jav a 2 s .  co m*/
        while (secondsString.length() < 2) {
            secondsString = "0" + secondsString;
        }
        return (hours == 0 ? "" : hoursString + ":") + minutesString + ":" + secondsString + "." + millisString;
    }
}

Related

  1. formatTime(long millis)
  2. formatTimeInMillis(long millis)
  3. formatTimeMillis(long millis)
  4. formatTimeMillis(long timeMillis)
  5. formatTimestamp(long millis)
  6. getFormatedDateTime(long millis)
  7. getFormattedAPILastAccessDate(long lastAccessTimeMillis)
  8. getMillisAsFormattedSeconds(long millis)
  9. getMvoDateFormatForMilliSecond()