Java Millisecond Convert convertTimeToDurationMilliseconds(String time)

Here you can find the source of convertTimeToDurationMilliseconds(String time)

Description

Convert a time string in format HH:MM:SS in a milliseconds duration.

License

Open Source License

Parameter

Parameter Description
time the time

Declaration

public static long convertTimeToDurationMilliseconds(String time) 

Method Source Code

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

public class Main {
    /**//from  w w  w  .j  a  v a2 s  . c o m
     * Convert a time string in format HH:MM:SS in a milliseconds duration.
     * 
     * @param time
     *          the time
     * @return
     */
    public static long convertTimeToDurationMilliseconds(String time) {
        long retObj = 0;

        if (time != null) {
            try {
                Integer hours = Integer.valueOf(time.substring(0, 2));
                Integer minutes = Integer.valueOf(time.substring(3, 5));
                Integer seconds = Integer.valueOf(time.substring(6, 8));
                retObj += hours * 60 * 60 * 1000;
                retObj += minutes * 60 * 1000;
                retObj += seconds * 1000;
            } catch (NumberFormatException e) {

            }
        }

        return retObj;
    }
}

Related

  1. convertMillisToString(long diff)
  2. convertMillisToTicks(long milliseconds)
  3. convertMillisToTime(String val)
  4. convertNanosecondToMillisecondString(final long nanos)
  5. convertTimeMillisToHexString(long currentDate)
  6. convertToMillis(float timeInSeconds)
  7. convertToMillis(String time)
  8. convertToMilliseconds(String value)
  9. getDuration(final long millis)