Class CalendarUtils

java.lang.Object
com.aoapps.lang.util.CalendarUtils

public final class CalendarUtils extends Object
Calendar utilities.
Author:
AO Industries, Inc.
  • Method Details

    • formatDate

      public static String formatDate(Calendar cal)
      Formats a date in "YYYY-MM-DD" format.
      Returns:
      the formatted date or null if the parameter is null
    • formatDate

      public static void formatDate(Calendar cal, Appendable out) throws IOException
      Formats a date in "YYYY-MM-DD" format.
      Throws:
      IOException
    • parseDate

      public static GregorianCalendar parseDate(String yyyy_mm_dd, TimeZone timeZone) throws IllegalArgumentException
      Gets the date from the "YYYY-MM-DD" format in the given time zone or null if the parameter is null. Allows negative years like "-344-01-23". Allows shorter months and days like "1976-1-9".
      Parameters:
      yyyy_mm_dd - The date in YYYY-MM-DD format.
      timeZone - The time zone to use or null to use the default time zone
      Throws:
      IllegalArgumentException
    • parseDate

      public static GregorianCalendar parseDate(String yyyy_mm_dd) throws IllegalArgumentException
      Gets the date from the "YYYY-MM-DD" format in the default time zone or null if the parameter is null. Allows negative years like "-344-01-23". Allows shorter months and days like "1976-1-9".
      Parameters:
      yyyy_mm_dd - The date in YYYY-MM-DD format.
      Throws:
      IllegalArgumentException
    • formatTime

      public static String formatTime(Calendar cal)
      Formats a time in "HH:MM:SS" format.
      Returns:
      the formatted time or null if the parameter is null
    • formatTime

      public static void formatTime(Calendar cal, Appendable out) throws IOException
      Formats a time in "HH:MM:SS" format.
      Throws:
      IOException
    • formatDateTime

      public static String formatDateTime(Calendar cal)
      Formats a date and time in "YYYY-MM-DD HH:MM:SS" format.
      Returns:
      the formatted date and time or null if the parameter is null
    • formatDateTime

      public static void formatDateTime(Calendar cal, Appendable out) throws IOException
      Formats a date and time in "YYYY-MM-DD HH:MM:SS" format.
      Throws:
      IOException
    • parseDateTime

      public static <T> T parseDateTime(String dateTime, TimeZone timeZone, CalendarUtils.DateTimeProducer<T> producer) throws IllegalArgumentException
      Gets the date and time from the "YYYY-MM-DD[ HH:MM[:SS[.nnnnnnnnn]]]" format in the given time zone or null if the parameter is null. Allows negative years like "-344-01-23". Allows shorter months, days, hours, minutes, and millis like "1976-1-9 1:2:3.1".
      Parameters:
      timeZone - The time zone to use or null to use the default time zone
      Throws:
      IllegalArgumentException
    • parseDateTime

      public static GregorianCalendar parseDateTime(String dateTime, TimeZone timeZone) throws IllegalArgumentException
      Gets the date and time from the "YYYY-MM-DD[ HH:MM[:SS[.mmm]]]" format in the given time zone or null if the parameter is null. Allows negative years like "-344-01-23". Allows shorter months, days, hours, minutes, and millis like "1976-1-9 1:2:3.1".
      Parameters:
      timeZone - The time zone to use or null to use the default time zone
      Throws:
      IllegalArgumentException
    • parseDateTime

      public static GregorianCalendar parseDateTime(String dateTime) throws IllegalArgumentException
      Gets the date and time from the "YYYY-MM-DD[ HH:MM[:SS[.mmm]]]" format in the default time zone or null if the parameter is null. Allows negative years like "-344-01-23". Allows shorter months, days, hours, minutes, and millis like "1976-1-9 1:2:3.1".
      Throws:
      IllegalArgumentException
    • getToday

      public static GregorianCalendar getToday(TimeZone timeZone)
      Gets today's date in the given time zone. Hour, minute, second, and millisecond are all set to zero.
      Parameters:
      timeZone - The time zone to use or null to use the default time zone
    • getToday

      public static GregorianCalendar getToday()
      Gets today's date in the default time zone. Hour, minute, second, and millisecond are all set to zero.