Here you can find the source of getUnitLengthSeconds(String unit)
Parameter | Description |
---|---|
unit | A string representing the unit. This accepts seconds, minutes, hours and days, and should be constant across calendar systems. |
public static int getUnitLengthSeconds(String unit)
//package com.java2s; public class Main { /**/*from ww w . ja v a 2 s . c om*/ * @param unit * A string representing the unit. This accepts seconds, minutes, * hours and days, and should be constant across calendar * systems. * @return The length of the given unit in seconds. */ public static int getUnitLengthSeconds(String unit) { unit = unit.trim(); if (unit.equals("seconds") || unit.equals("second") || unit.equals("secs") || unit.equals("sec") || unit.equals("s")) { return 1; } else if (unit.equals("minutes") || unit.equals("minute") || unit.equals("mins") || unit.equals("min")) { return 60; } else if (unit.equals("hours") || unit.equals("hour") || unit.equals("hrs") || unit.equals("hr") || unit.equals("h")) { return 60 * 60; } else if (unit.equals("days") || unit.equals("day") || unit.equals("d")) { return 60 * 60 * 24; } else { throw new IllegalArgumentException("Unrecognized unit: " + unit); } } }