Package emissary.util
Class TimeUtil
- java.lang.Object
-
- emissary.util.TimeUtil
-
public class TimeUtil extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static DateTimeFormatter
DATE_FULL_ISO_8601
static DateTimeFormatter
DATE_ISO_8601
static DateTimeFormatter
DATE_ISO_8601_SSS
static DateTimeFormatter
DATE_ORDINAL
static DateTimeFormatter
DATE_ORDINAL_WITH_TIME
static DateTimeFormatter
DATE_WITH_SLASHES
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static String
convertHexDate(String hexDate)
Parses hex date string into formatted string ("yyyy-MM-dd HH:mm:ss.SSS")static String
getCurrentDate()
Get current date/time as a slash separated path component (yyyy-MM-dd/HH/mm)static String
getCurrentDateFullISO8601()
Get current date/time as full ISO-8601 string yyyy-MM-dd'T'HH:mm:ss'Z'static String
getCurrentDateISO8601()
Get current date/time as ISO-8601 stringstatic String
getCurrentDateOrdinal()
Get current date as yyyyjjjstatic String
getDate(String format, String timeZone)
Get current date/time formatted as specifiedstatic String
getDate(TemporalAccessor date, String format, ZoneId timeZone)
Given a date, format it with the given patternstatic String
getDateAsFullISO8601(TemporalAccessor date)
Get specified date object as a full ISO-8601 string (yyyy-MM-dd'T'HH:mm:ss'Z')static String
getDateAsISO8601(long time)
Get specified time as ISO-8601 stringstatic String
getDateAsISO8601(TemporalAccessor date)
Get specified date object as ISO-8601 string (yyyy-MM-dd HH:mm:ss)static String
getDateAsPath(TemporalAccessor date)
Get specified date/time as a slash separated path component (yyyy-MM-dd/HH/mm)static String
getDateOrdinal(TemporalAccessor date)
Get current date as yyyyjjjstatic String
getDateOrdinalWithTime(Instant d)
static String
getISO8601DateFormatString()
static ZoneId
getTimezone()
Get the application configured timezonestatic ZonedDateTime
getZonedDateFromISO8601(String dateString)
Deprecated.replaced byFlexibleDateTimeParser.parse(String)
-
-
-
Field Detail
-
DATE_WITH_SLASHES
public static final DateTimeFormatter DATE_WITH_SLASHES
-
DATE_ISO_8601
public static final DateTimeFormatter DATE_ISO_8601
-
DATE_FULL_ISO_8601
public static final DateTimeFormatter DATE_FULL_ISO_8601
-
DATE_ORDINAL
public static final DateTimeFormatter DATE_ORDINAL
-
DATE_ISO_8601_SSS
public static final DateTimeFormatter DATE_ISO_8601_SSS
-
DATE_ORDINAL_WITH_TIME
public static final DateTimeFormatter DATE_ORDINAL_WITH_TIME
-
-
Method Detail
-
getTimezone
public static ZoneId getTimezone()
Get the application configured timezone- Returns:
- the timezone
-
getDate
public static String getDate(String format, @Nullable String timeZone)
Get current date/time formatted as specified- Parameters:
format
- the specificationtimeZone
- tz to use, defaults to GMT- Throws:
DateTimeException
- if the ID format is invalidZoneRulesException
- if checking availability and the zone ID cannot be foundIllegalArgumentException
- if the pattern is invalid
-
getDate
@Nullable public static String getDate(@Nullable TemporalAccessor date, String format, @Nullable ZoneId timeZone)
Given a date, format it with the given pattern- Parameters:
date
- the date to formatformat
- the date formattimeZone
- the time zone id- Returns:
- the formatted date
- Throws:
DateTimeException
- if the ID format is invalidZoneRulesException
- if checking availability and the zone ID cannot be foundIllegalArgumentException
- if the pattern is invalid
-
getCurrentDate
public static String getCurrentDate()
Get current date/time as a slash separated path component (yyyy-MM-dd/HH/mm)- Returns:
- the formatted date in the form yyyy-MM-dd/HH/mm
- Throws:
DateTimeException
- if an error occurs during formatting
-
getDateAsPath
@Nullable public static String getDateAsPath(@Nullable TemporalAccessor date)
Get specified date/time as a slash separated path component (yyyy-MM-dd/HH/mm)- Parameters:
date
- to format- Returns:
- the formatted date in the form yyyy-MM-dd/HH/mm
- Throws:
DateTimeException
- if an error occurs during formatting
-
getCurrentDateOrdinal
public static String getCurrentDateOrdinal()
Get current date as yyyyjjj- Returns:
- the formatted date in the form yyyyjjj
- Throws:
DateTimeException
- if an error occurs during formatting
-
getDateOrdinal
@Nullable public static String getDateOrdinal(@Nullable TemporalAccessor date)
Get current date as yyyyjjj- Parameters:
date
- to format- Returns:
- the formatted date in the form yyyyjjj
- Throws:
DateTimeException
- if an error occurs during formatting
-
getCurrentDateISO8601
public static String getCurrentDateISO8601()
Get current date/time as ISO-8601 string- Returns:
- String in the format yyyy-MM-dd HH:mm:ss
- Throws:
DateTimeException
- if an error occurs during formatting
-
getDateAsISO8601
public static String getDateAsISO8601(long time)
Get specified time as ISO-8601 string- Returns:
- String in the format yyyy-MM-dd HH:mm:ss
- Throws:
DateTimeException
- if an error occurs during formatting
-
getDateAsISO8601
@Nullable public static String getDateAsISO8601(@Nullable TemporalAccessor date)
Get specified date object as ISO-8601 string (yyyy-MM-dd HH:mm:ss)- Parameters:
date
- to format- Returns:
- String in the format yyyy-MM-dd HH:mm:ss
- Throws:
DateTimeException
- if an error occurs during formatting
-
getCurrentDateFullISO8601
public static String getCurrentDateFullISO8601()
Get current date/time as full ISO-8601 string yyyy-MM-dd'T'HH:mm:ss'Z'- Returns:
- String in the format yyyy-MM-dd'T'HH:mm:ss'Z'
- Throws:
DateTimeException
- if an error occurs during formatting
-
getDateAsFullISO8601
@Nullable public static String getDateAsFullISO8601(@Nullable TemporalAccessor date)
Get specified date object as a full ISO-8601 string (yyyy-MM-dd'T'HH:mm:ss'Z')- Parameters:
date
- to format- Returns:
- the formatted date in yyyy-MM-dd'T'HH:mm:ss'Z'
- Throws:
DateTimeException
- if an error occurs during formatting
-
getZonedDateFromISO8601
@Nullable @Deprecated public static ZonedDateTime getZonedDateFromISO8601(@Nullable String dateString)
Deprecated.replaced byFlexibleDateTimeParser.parse(String)
Get Date object from ISO-8601 formatted string ("yyyy-MM-dd HH:mm:ss")- Parameters:
dateString
- the string representation of the date in the format yyyy-MM-dd HH:mm:ss- Returns:
- ZonedDateTime parsed from the string
- Throws:
DateTimeParseException
- if string is not in the proper format
-
convertHexDate
public static String convertHexDate(String hexDate)
Parses hex date string into formatted string ("yyyy-MM-dd HH:mm:ss.SSS")- Parameters:
hexDate
- hex string representation of the date- Returns:
- converted time in string format yyyy-MM-dd HH:mm:ss.SSS
- Throws:
DateTimeParseException
- if could not parse date
-
getISO8601DateFormatString
public static String getISO8601DateFormatString()
-
-