Java Milliseconds getUnitLengthMillis(String unit)

Here you can find the source of getUnitLengthMillis(String unit)

Description

Gets the length of the given unit in milliseconds.

License

Open Source License

Declaration

public static long getUnitLengthMillis(String unit) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from  w ww.  j  av a2s.  c o  m
     * Gets the length of the given unit in milliseconds.  This accepts
     * seconds, minutes, hours and days, and should be constant across calendar
     * systems.
     */
    public static long getUnitLengthMillis(String unit) {
        unit = unit.trim();
        if (unit.equals("seconds") || unit.equals("second") || unit.equals("secs") || unit.equals("sec")
                || unit.equals("s")) {
            return 1000;
        } else if (unit.equals("minutes") || unit.equals("minute") || unit.equals("mins") || unit.equals("min")) {
            return 1000 * 60;
        } else if (unit.equals("hours") || unit.equals("hour") || unit.equals("hrs") || unit.equals("hr")
                || unit.equals("h")) {
            return 1000 * 60 * 60;
        } else if (unit.equals("days") || unit.equals("day") || unit.equals("d")) {
            return 1000 * 60 * 60 * 24;
        } else {
            throw new IllegalArgumentException("Unrecognized unit for time axis: " + unit);
        }
    }
}

Related

  1. getOLEDateFromMillisRounded(long millis)
  2. getPeriodDurationInMillis(int period)
  3. GetTimeInMilliseconds(Date date)
  4. getTimeStringFromMilliseconds(long millis)
  5. getTimeZoneOffSetInMillisecond(String dateString)
  6. hasExpiredMillis(long now, long eventTime, long timeBuffer)
  7. hhmmssToMillis(String text)
  8. humanDateToMillisecondsWithoutException(String date)
  9. isSameSecondOfMillis(final long ms1, final long ms2)