Java Second Parse parseTimeStringAsSeconds(String timeString)

Here you can find the source of parseTimeStringAsSeconds(String timeString)

Description

parse Time String As Seconds

License

Open Source License

Declaration

static public int parseTimeStringAsSeconds(String timeString) 

Method Source Code

//package com.java2s;
// This software is published under the terms of the MIT license, a copy

public class Main {
    static public int parseTimeStringAsSeconds(String timeString) {
        int seconds;
        String[] timeComponents = timeString.split(":");
        if (timeComponents.length == 0) {
            seconds = 0;//from  www  .  j a  v a  2s .  co  m
        } else if (timeComponents.length == 1) {
            seconds = Integer.parseInt(timeComponents[0]) * 60;
        } else if (timeComponents.length == 2) {
            int minutes = 0;
            if (!timeComponents[0].equals("")) {
                minutes = Integer.parseInt(timeComponents[0]);
            }
            seconds = Integer.parseInt(timeComponents[1]) + (60 * minutes);
        } else {
            seconds = 0;
        }
        return seconds;
    }
}

Related

  1. centisecondsPerTick(final int tps)
  2. parseHHMMSSToSeconds(String txt)
  3. parseSeconds(String value, int defaultValue)
  4. parseW3CDateWithFractionalSeconds(String dateString)