Package org.kissweb

Class DateTime

java.lang.Object
org.kissweb.DateTime

public class DateTime extends Object
Class dealing with dates with times.
  • Constructor Details

    • DateTime

      public DateTime(ZonedDateTime dt)
      Create a DateTime object from a ZonedDateTime object
      Parameters:
      dt -
    • DateTime

      public DateTime(long millisecs)
      Create a DateTime object from the number of milliseconds since 1970 (Epoch).
      Parameters:
      millisecs -
    • DateTime

      public DateTime(int dt, int time)
      Create a DateTime object from a date (YYYYMMDD) and time (HHMM)
      Parameters:
      dt - YYYYMMDD
      time - HHMM
    • DateTime

      public DateTime(int dt, int time, String timeZoneId)
      Create a DateTime object from a date (YYYYMMDD) and time (HHMM) in the specified time zone.
      Parameters:
      dt - YYYYMMDD
      time - HHMM
      timeZoneId -
    • DateTime

      public DateTime(Date dt)
      Create a DateTime from a Date object.
      Parameters:
      dt -
    • DateTime

      public DateTime(GregorianCalendar dt)
      Initialize a new DateTime from a GregorianCalendar
      Parameters:
      dt -
  • Method Details

    • now

      public static DateTime now()
      Create a new DateTime object that represents the current date/time.
      Returns:
    • now

      public static DateTime now(String timeZoneId)
      Create a new DateTime object that represents the current date/time in the specified time zone.
      Parameters:
      timeZoneId - The time zone ID to use. Examples include "America/New_York", "America/Chicago", "Europe/London", etc.
      Returns:
    • changeTimeZone

      public DateTime changeTimeZone(String timeZoneId)
      Changes the time zone associated with this DateTime object to the specified time zone and returns the modified DateTime object.

      The date and time remain the same, but the time zone is changed to the new one.
      Parameters:
      timeZoneId - The ID of the new time zone. Examples include "America/New_York", "America/Chicago", "Europe/London", etc.
      Returns:
      This DateTime object, now with the new time zone.
    • getYear

      public int getYear()
      Get the year portion of a DateTime
      Returns:
      YYYY
    • getMonth

      public int getMonth()
      Return the month portion of a DateTime
      Returns:
      1-12
    • getDay

      public int getDay()
      Return the day of the month
      Returns:
      (1-31)
    • getHour

      public int getHour()
      Return the hour portion of a DateTime
      Returns:
      (0-23)
    • getMinute

      public int getMinute()
      Return the minute portion of a DateTime
      Returns:
      (0-59)
    • getDate

      public Date getDate()
      Get a Date representation of the DateTime object.
      Returns:
    • getIntDate

      public int getIntDate()
      Get date in an int format YYYYMMDD
      Returns:
    • getIntTime

      public int getIntTime()
      Return an integer representation of the date portion.
      Returns:
      HHMM
    • getZonedDateTime

      public ZonedDateTime getZonedDateTime()
      Return the ZoneDateTime object
      Returns:
    • format

      public String format()
      Return the current date formatted as mm/dd/yyyy hh:mm AM/PM
      Returns:
    • currentDateTimeFormatted

      public static String currentDateTimeFormatted()
      Return the current date and time as a string mm/dd/yyyy hh:mm AM/PM
      Returns:
    • currentDateTimeFormattedTZ

      public static String currentDateTimeFormattedTZ()
      Return the current date and time as a string mm/dd/yyyy hh:mm AM/PM cST
      Returns:
    • format

      public static String format(Date date)
      Format a date passed into a string mm/dd/yyyy hh:mm AM/PM
      Parameters:
      date -
      Returns:
    • format

      public static String format(ZonedDateTime date)
      Format a date passed into a string mm/dd/yyyy hh:mm AM/PM.
      Parameters:
      date - The date to format.
      Returns:
      The formatted string.
    • format

      public static String format(ZonedDateTime date, String fmt)
      Format a date passed into a string according to a format specification.
      Parameters:
      date - The date to format.
      fmt - The format string.
      Returns:
      The formatted string.
    • format

      public static String format(Date date, String fmt, String timeZoneId)
      Format a date passed into a string according to a format specification.
      Parameters:
      date - The date to format.
      fmt - The format string.
      timeZoneId - The ID of the time zone to use when formatting the date. If not null or empty, the time zone is set to that zone before formatting.
      Returns:
      The formatted string.
    • format

      public static String format(ZonedDateTime dateTime, String fmt, String timeZoneId)
      Format a ZonedDateTime into a string using the given format string. If timeZoneId is not null or empty, the time zone is set to that zone before formatting.
      Parameters:
      dateTime - The ZonedDateTime to format
      fmt - The format string
      timeZoneId - The time zone ID to use, if not null or empty
      Returns:
      The formatted string
    • format

      public static String format(Date date, String fmt)
      Format a date passed into a string formatted as determined by fmt
      Parameters:
      date -
      fmt -
      Returns:
      See Also:
    • formatTZ

      public static String formatTZ(Date date)
      Format a date passed into a string mm/dd/yyyy hh:mm AM/PM xST
      Parameters:
      date -
      Returns:
    • currentDateTimeFormatted

      public static String currentDateTimeFormatted(String dateFormat, String timeZone)
      Returns a string representing the current date and/or time with a specified format and within a specified timezone.
      Parameters:
      dateFormat -
      timeZone -
      Returns:
      See Also:
    • currentDateTimeFormatted

      public static String currentDateTimeFormatted(String dateFormat)
      Returns a string representing the current date and/or time with a specified format.
      Parameters:
      dateFormat -
      Returns:
      See Also:
    • getMilliseconds

      public long getMilliseconds()
      Returns number of milliseconds since 1970 UTC.
      Returns:
    • getSeconds

      public long getSeconds()
      Returns number of seconds since 1970 UTC.
      Returns:
    • addDays

      public DateTime addDays(int days)
      Add days to a DateTime object.
      Parameters:
      days - the number of days to add - can be negative
      Returns:
    • main

      public static void main(String[] args)