Package org.rapidcontext.util
Class DateUtil
java.lang.Object
org.rapidcontext.util.DateUtil
A set of utility methods for handling date and time objects.
- Version:
- 1.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
asDateTimeUTC
(Date date) Formats a date and time in an ISO 8601 datetime representation for the UTC timezone.static String
asEpochMillis
(Date date) Formats a date and time in Unix (millisecond) epoch format (i.e.static String
formatIsoDateTime
(Date date) Formats a date and time to an ISO datetime representation (without timezone).static String
formatIsoTime
(Date date) Formats a time to an ISO time representation (without timezone).static boolean
isEpochFormat
(String str) Checks if a string is in Unix epoch format.
-
Method Details
-
isEpochFormat
Checks if a string is in Unix epoch format. Note that there is no safe way to distinguish between epoch values in second vs. millisecond resolution for all cases.- Parameters:
str
- the string to test- Returns:
- true if the string is in epoch format, or false otherwise
-
asEpochMillis
Formats a date and time in Unix (millisecond) epoch format (i.e. "@1653037430316").- Parameters:
date
- the date and time to convert- Returns:
- the epoch millisecond string
-
asDateTimeUTC
Formats a date and time in an ISO 8601 datetime representation for the UTC timezone.- Parameters:
date
- the date and time to convert- Returns:
- the ISO 8601 datetime string in UTC
-
formatIsoDateTime
Formats a date and time to an ISO datetime representation (without timezone).- Parameters:
date
- the date and time to convert- Returns:
- the ISO datetime string
-
formatIsoTime
Formats a time to an ISO time representation (without timezone).- Parameters:
date
- the date and time to convert- Returns:
- the ISO time string
-