java.lang.Object
com.aoapps.lang.util.CalendarUtils
Calendar utilities.
- Author:
- AO Industries, Inc.
-
Nested Class Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
formatDate
(Calendar cal) Formats a date in "YYYY-MM-DD" format.static void
formatDate
(Calendar cal, Appendable out) Formats a date in "YYYY-MM-DD" format.static String
formatDateTime
(Calendar cal) Formats a date and time in "YYYY-MM-DD HH:MM:SS" format.static void
formatDateTime
(Calendar cal, Appendable out) Formats a date and time in "YYYY-MM-DD HH:MM:SS" format.static String
formatTime
(Calendar cal) Formats a time in "HH:MM:SS" format.static void
formatTime
(Calendar cal, Appendable out) Formats a time in "HH:MM:SS" format.static GregorianCalendar
getToday()
Gets today's date in the default time zone.static GregorianCalendar
Gets today's date in the given time zone.static GregorianCalendar
Gets the date from the "YYYY-MM-DD" format in the default time zone ornull
if the parameter isnull
.static GregorianCalendar
Gets the date from the "YYYY-MM-DD" format in the given time zone ornull
if the parameter isnull
.static GregorianCalendar
parseDateTime
(String dateTime) Gets the date and time from the "YYYY-MM-DD[ HH:MM[:SS[.mmm]]]" format in the default time zone ornull
if the parameter isnull
.static GregorianCalendar
parseDateTime
(String dateTime, TimeZone timeZone) Gets the date and time from the "YYYY-MM-DD[ HH:MM[:SS[.mmm]]]" format in the given time zone ornull
if the parameter isnull
.static <T> T
parseDateTime
(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 ornull
if the parameter isnull
.
-
Method Details
-
formatDate
Formats a date in "YYYY-MM-DD" format.- Returns:
- the formatted date or
null
if 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 ornull
if 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 ornull
to use the default time zone- Throws:
IllegalArgumentException
-
parseDate
Gets the date from the "YYYY-MM-DD" format in the default time zone ornull
if 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
null
if 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
null
if 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 ornull
if 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 ornull
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 ornull
if 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 ornull
to 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 ornull
if 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 ornull
to 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.
-