java.lang.Object
com.aoapps.lang.util.CalendarUtils
Calendar utilities.
- Author:
- AO Industries, Inc.
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic StringformatDate(Calendar cal) Formats a date in "YYYY-MM-DD" format.static voidformatDate(Calendar cal, Appendable out) Formats a date in "YYYY-MM-DD" format.static StringformatDateTime(Calendar cal) Formats a date and time in "YYYY-MM-DD HH:MM:SS" format.static voidformatDateTime(Calendar cal, Appendable out) Formats a date and time in "YYYY-MM-DD HH:MM:SS" format.static StringformatTime(Calendar cal) Formats a time in "HH:MM:SS" format.static voidformatTime(Calendar cal, Appendable out) Formats a time in "HH:MM:SS" format.static GregorianCalendargetToday()Gets today's date in the default time zone.static GregorianCalendarGets today's date in the given time zone.static GregorianCalendarGets the date from the "YYYY-MM-DD" format in the default time zone ornullif the parameter isnull.static GregorianCalendarGets the date from the "YYYY-MM-DD" format in the given time zone ornullif the parameter isnull.static GregorianCalendarparseDateTime(String dateTime) Gets the date and time from the "YYYY-MM-DD[ HH:MM[:SS[.mmm]]]" format in the default time zone ornullif the parameter isnull.static GregorianCalendarparseDateTime(String dateTime, TimeZone timeZone) Gets the date and time from the "YYYY-MM-DD[ HH:MM[:SS[.mmm]]]" format in the given time zone ornullif the parameter isnull.static <T> TparseDateTime(String dateTime, TimeZone timeZone, CalendarUtils.DateTimeProducer<T> producer) Gets the date and time from the "YYYY-MM-DD[ HH:MM[:SS[.nnnnnnnnn]]]" format in the given time zone ornullif the parameter isnull.
-
Method Details
-
formatDate
Formats a date in "YYYY-MM-DD" format.- Returns:
- the formatted date or
nullif the parameter isnull
-
formatDate
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 ornullif the parameter isnull. 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 ornullto use the default time zone- Throws:
IllegalArgumentException
-
parseDate
Gets the date from the "YYYY-MM-DD" format in the default time zone ornullif the parameter isnull. 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
Formats a time in "HH:MM:SS" format.- Returns:
- the formatted time or
nullif the parameter isnull
-
formatTime
Formats a time in "HH:MM:SS" format.- Throws:
IOException
-
formatDateTime
Formats a date and time in "YYYY-MM-DD HH:MM:SS" format.- Returns:
- the formatted date and time or
nullif the parameter isnull
-
formatDateTime
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 ornullif the parameter isnull. 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 ornullto 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 ornullif the parameter isnull. 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 ornullto use the default time zone- Throws:
IllegalArgumentException
-
parseDateTime
Gets the date and time from the "YYYY-MM-DD[ HH:MM[:SS[.mmm]]]" format in the default time zone ornullif the parameter isnull. 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
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 ornullto use the default time zone
-
getToday
Gets today's date in the default time zone. Hour, minute, second, and millisecond are all set to zero.
-
