Package org.kissweb
Class TimeUtils
java.lang.Object
org.kissweb.TimeUtils
TimeUtils class. Deals with time represented as an int formatted as HHMM.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
formatAMPM
(int tm) Format time as hh:mm AM/PMstatic String
formatMilitary
(int tm) Format time as hh:mm (hours to 23)static int
hour
(int time) Return the hour portion of a time HHMMstatic void
static int
minutes
(int time) Return the minute portion of a time HHMMstatic int
now()
Returns the current time of day in the format HHMM since midnight.static int
Returns the current time in a given timezone in the format HHMM since midnight.static int
Parse a string into an int representing a time in the form HHMM.
-
Constructor Details
-
TimeUtils
public TimeUtils()
-
-
Method Details
-
now
public static int now()Returns the current time of day in the format HHMM since midnight. -
now
Returns the current time in a given timezone in the format HHMM since midnight.- Parameters:
timeZoneId
- the timezone to use- Returns:
- the current time in the given timezone as an int formatted as HHMM
-
formatMilitary
Format time as hh:mm (hours to 23)- Parameters:
tm
- HHMM- Returns:
-
formatAMPM
Format time as hh:mm AM/PM- Parameters:
tm
- HHMM- Returns:
-
hour
public static int hour(int time) Return the hour portion of a time HHMM- Parameters:
time
- HHMM- Returns:
- HH
-
minutes
public static int minutes(int time) Return the minute portion of a time HHMM- Parameters:
time
- HHMM- Returns:
- MM
-
parse
Parse a string into an int representing a time in the form HHMM. Intelligently parses the strings, for example:
"330" -> 330
"0330" -> 330
"3:30" -> 330
"3.30" -> 330
"230 pm" -> 1430
"14:30" -> 1430- Parameters:
time
-- Returns:
- time as HHMM or -1 on error
-
main
-