Package de.aristaflow.adept2.util.time
Class DateTimeFormat
java.lang.Object
de.aristaflow.adept2.util.time.DateTimeFormat
Simple tool class featuring simple formatting of relative and absolute
times. A time stamp is considered as being relative, if it is <= 0.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringformatDate(long timestamp) Returns a formatted date.static StringformatDateTime(long dateTime) Format the given timestamp either as absolute date or a relative time, depending on the signature of the value.static StringformatTime(long time) Returns a formatted string representing the relative time.static longConverts the entered time string into milliseconds, e. g.
-
Constructor Details
-
DateTimeFormat
public DateTimeFormat()
-
-
Method Details
-
formatDateTime
Format the given timestamp either as absolute date or a relative time, depending on the signature of the value.- Parameters:
dateTime-- Returns:
- A formatted time.
-
formatTime
Returns a formatted string representing the relative time.
This is similar toString.format("%2$sw %1$tHh %1$tMmin %1$tSs %1$tLms", timestamp, timestamp/1000/60/60/24/7). but without leading zeros.- Parameters:
time-- Returns:
- A formatted string representing the relative time.
-
formatDate
Returns a formatted date.
This equalsString.format("%1$tc", timestamp).- Parameters:
timestamp-- Returns:
- A formatted date.
-
toMillis
Converts the entered time string into milliseconds, e. g. "2h 3min" are7380000milliseconds. This removes any white space. The units need to be in ascending order.- Parameters:
strDuration- The duration as string.- Returns:
- The designated duration in milliseconds.
- Throws:
DateTimeParseException- If the designated string cannot be parsed to a duration. aDateTimeParseExceptionwill be thrown.
-