Package de.aristaflow.adept2.util.time
Class DateTimeFormat
- java.lang.Object
-
- de.aristaflow.adept2.util.time.DateTimeFormat
-
public class DateTimeFormat extends Object
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 Constructor Description DateTimeFormat()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
formatDate(long timestamp)
Returns a formatted date.static String
formatDateTime(long dateTime)
Format the given timestamp either as absolute date or a relative time, depending on the signature of the value.static String
formatTime(long time)
Returns a formatted string representing the relative time.static long
toMillis(String strDuration)
Converts the entered time string into milliseconds, e. g.
-
-
-
Method Detail
-
formatDateTime
public static String formatDateTime(long dateTime)
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
public static String formatTime(long time)
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
public static String formatDate(long timestamp)
Returns a formatted date.
This equalsString.format("%1$tc", timestamp)
.- Parameters:
timestamp
-- Returns:
- A formatted date.
-
toMillis
public static long toMillis(String strDuration)
Converts the entered time string into milliseconds, e. g. "2h 3min" are7380000
milliseconds. 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. aDateTimeParseException
will be thrown.
-
-