Java Minute Convert convertMinutesSecondsToMilliseconds(String offset)

Here you can find the source of convertMinutesSecondsToMilliseconds(String offset)

Description

Given a string of the form mm:ss, returns the total milliseconds

License

Apache License

Declaration

static public int convertMinutesSecondsToMilliseconds(String offset)
        throws NumberFormatException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.*;

public class Main {
    /**//from   w ww  .j a  v a  2 s  .c  o  m
     * Given a string of the form mm:ss, returns the total milliseconds
     */
    static public int convertMinutesSecondsToMilliseconds(String offset)
            throws NumberFormatException {
        boolean isOK = true;
        StringTokenizer tokenizer = new StringTokenizer(offset, ":");
        String token = null;

        int first = -1;
        int second = -1;

        try {
            token = tokenizer.nextToken();
        } catch (NoSuchElementException e) {
            isOK = false;
        }
        try {
            first = Integer.parseInt(token);
        } catch (NumberFormatException e) {
            isOK = false;
        }

        try {
            token = tokenizer.nextToken();
        } catch (NoSuchElementException e) {
            isOK = false;
        }
        try {
            second = Integer.parseInt(token);
        } catch (NumberFormatException e) {
            isOK = false;
        }

        if (!isOK) {
            throw new NumberFormatException();
        }
        return ((first * 60000) + (second * 1000));
    }
}

Related

  1. convertHoursToMinutes(Double hours)
  2. convertHoursToMinutes(final int hours)
  3. convertMillisToHoursMinutesSeconds(long offset)
  4. convertMinute(String targetHhMm)
  5. convertMinuteSecond(double minute, double second)
  6. convertMinutesToMilliseconds(final long minutes)
  7. convertMinutesToSeconds(final long minutes)
  8. convertMinutesToSeconds(int minutesToConvert)
  9. convertMsToMinutesAndSeconds(long ms)