Package org.kissweb

Class TimeUtils

java.lang.Object
org.kissweb.TimeUtils

public class TimeUtils extends Object
TimeUtils class. Deals with time represented as an int formatted as HHMM.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    formatAMPM(int tm)
    Format time as hh:mm AM/PM
    static String
    Format time as hh:mm (hours to 23)
    static int
    hour(int time)
    Return the hour portion of a time HHMM
    static void
    main(String[] argv)
     
    static int
    minutes(int time)
    Return the minute portion of a time HHMM
    static int
    now()
    Returns the current time of day in the format HHMM since midnight.
    static int
    now(String timeZoneId)
    Returns the current time in a given timezone in the format HHMM since midnight.
    static int
    parse(String time)
    Parse a string into an int representing a time in the form HHMM.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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

      public static int now(String timeZoneId)
      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

      public static String formatMilitary(int tm)
      Format time as hh:mm (hours to 23)
      Parameters:
      tm - HHMM
      Returns:
    • formatAMPM

      public static String formatAMPM(int tm)
      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

      public static int parse(String time)
      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

      public static void main(String[] argv)