Java Second to Minute timeToMinute(String time)

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

Description

time To Minute

License

Open Source License

Declaration

public static int timeToMinute(String time) 

Method Source Code

//package com.java2s;

public class Main {
    public static int timeToMinute(String time) {

        // find split between hour and minute
        int mark = time.indexOf(':');
        if (mark > 0) {

            // convert hour to adjusted range (0-11)
            int hour = Integer.parseInt(time.substring(0, mark));
            if (hour == 12) {
                hour = 0;/*from   ww  w  .j  ava  2s .  com*/
            }

            // find minute value
            String mins = time.substring(mark + 1, time.length() - 1);
            int minute = Integer.parseInt(mins);

            // check am/pm flag
            char last = time.charAt(time.length() - 1);
            boolean pm = Character.toLowerCase(last) == 'p';

            // return minute number of flight time
            return ((pm ? 12 : 0) + hour) * 60 + minute;

        } else {
            throw new IllegalArgumentException("Not a valid time: " + time);
        }
    }
}

Related

  1. secondsToHoursMinutesSeconds(final long secs)
  2. secondsToMinutes(int s)
  3. secondsToMinutes(int seconds)
  4. secondsToMinutes(int seconds)
  5. secondsToMinutes(int time)
  6. timeToMinutes(String in)
  7. toDecimal(long seconds, int nanoseconds)
  8. toDecimal(long seconds, int nanoseconds)
  9. toMinutes(int hour, int minutes)