Java Calendar Second getTimeSeconds(Calendar cal)

Here you can find the source of getTimeSeconds(Calendar cal)

Description

Wrapper for getTimeSeconds(int hour, int min).

License

Open Source License

Parameter

Parameter Description
cal the Calendar representing the time

Return

the number of seconds in the day

Declaration

public static int getTimeSeconds(Calendar cal) 

Method Source Code

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

import java.util.Calendar;

public class Main {
    /**//from w w  w  .j a  va2 s.c  o m
     * Get the number of seconds (in the day) for the specified time
     * in hours and minutes.  This returns 0 for 12:00 AM, 3600
     * for 1:00 AM, etc.
     * @param hour the 24 hour representation of the hours (can be 24+)
     * @param min the number of minutes in the hour
     * @return the number of seconds in the day
     */
    public static int getTimeSeconds(int hour, int min) {
        return (hour * 3600) + (min * 60);
    }

    /**
     * Wrapper for getTimeSeconds(int hour, int min).
     *
     * Get the number of seconds (in the day) for the specified time,
     * represented by the Calendar.  This returns 0 for 12:00 AM, 3600
     * for 1:00 AM, etc
     * @param cal the Calendar representing the time
     * @return the number of seconds in the day
     */
    public static int getTimeSeconds(Calendar cal) {
        return getTimeSeconds(cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE));
    }

    /**
     * Wrapper for getTimeSeconds(int hour, int min).
     *
     * Get the number of seconds (in the day) for the specified time,
     * represented by a GTFS 24+ hour time string.  This returns 0 for
     * 12:00 AM, 3600 for 1:00 AM, etc
     * @param gtfsTime HH:mm:ss time representation (HH can be > 24)
     * @return the number of seconds in the day
     */
    public static int getTimeSeconds(String gtfsTime) {
        String[] parts = gtfsTime.split(":");
        int hour = Integer.parseInt(parts[0]);
        int min = Integer.parseInt(parts[1]);
        return getTimeSeconds(hour, min);
    }
}

Related

  1. dateEquals(Calendar calendarFirst, Calendar calendarSecond)
  2. getSecond(Calendar calendar)
  3. getSecondsSinceMidnight(Calendar c)
  4. getSecondsSinceMidnight(final Calendar time)
  5. getTimeInSeconds(Calendar t)
  6. getTimestampInDayFirstSecond(final Calendar calendar)
  7. hasPassed10Second(Calendar time)
  8. isFirstAfterSecond(Calendar first, Calendar second)
  9. isSameSecond(Calendar c1, Calendar c2)