Java Minute Parse parseHourAndMinute(String value)

Here you can find the source of parseHourAndMinute(String value)

Description

parse Hour And Minute

License

Open Source License

Parameter

Parameter Description
value a parameter

Declaration

public static Long parseHourAndMinute(String value) 

Method Source Code

//package com.java2s;
// it under the terms of the GNU Affero General Public License as published by

public class Main {
    private static final long MILLIS_PER_MINUTE = 60L * 1000L;
    private static final long MILLIS_PER_HOUR = 60L * MILLIS_PER_MINUTE;

    /**//from   w  ww .  jav a  2s.  c  o  m
     * @param value
     * @return
     */
    public static Long parseHourAndMinute(String value) {
        value = value.trim();
        String[] comp = value.split(":");
        if (comp.length != 2) {
            return 0L; // invalid, should report as error...
        }
        try {
            int hours = Integer.parseInt(comp[0]);
            int minutes = Integer.parseInt(comp[1]);
            return (hours * MILLIS_PER_HOUR) + (minutes * MILLIS_PER_MINUTE);
        } catch (NumberFormatException e) {
            return 0L; // invalid, should report as error...
        }
    }
}

Related

  1. parseHHMMStringToMinutes(String time)
  2. parseIntForMinute(Integer i)
  3. parseMinutes(long time)
  4. parseMinutes(String minutes, int defaultValue)
  5. parseMinutes(String timeInMinutes)