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 Details

    • DateTimeFormat

      public DateTimeFormat()
  • Method Details

    • 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 to String.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 equals String.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" are 7380000 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. a DateTimeParseException will be thrown.