Class TimeUtils

java.lang.Object
com.tridion.util.TimeUtils

public final class TimeUtils extends Object
Contains utilities related to handling of time values.
  • Field Details

    • DATE_FORMAT

      public static final String DATE_FORMAT
      This is the internal date format used in the database.
      See Also:
  • Method Details

    • getDateTimeFormatter

      public static DateFormat getDateTimeFormatter()
      Creates a formatter for generating UTC DateTime strings. An example of the string representation of a DateTime string in ISO 8601 format is 2006-10-17T16:21:12Z. Note that DateFormats are not synchronized. It is recommended to create separate format instances for each thread.
      Returns:
      The formatter.
    • getRawDateTimeFormatter

      public static DateFormat getRawDateTimeFormatter()
      Get Raw date format for dates in format MMM dd, yyyy HH:mm:ss a like (Dec 29, 2016 9:25:31 AM).
      Returns:
      DateFormat
    • convertTimeToMs

      public static long convertTimeToMs(int value, String units)
      Converts a time value to milliseconds in a rather inflexible manner.
      Parameters:
      value - the value to convert.
      units - a string with one of the values "seconds", "minutes", or "hours".
      Returns:
      The converted value.
    • convertTimeToMs

      public static long convertTimeToMs(String text)
      Converts a time value to milliseconds. The time value is specified as a string that consists of one or more digits followed by an indication of the units: "s", "sec", or "seconds" for seconds; "m", "min" or "minutes" for minutes; "h" or "hours" for hours.
      Parameters:
      text - the time value to convert, in the format described above.
      Returns:
      The converted value, or -1 if the text does not satisfy the required format.
    • createInternalStringDate

      public static String createInternalStringDate(String stringDate, String dateFormat) throws ParseException
      Creates the internal representation of a date (e.g. in format yyyy-MM-dd HH:mm:ss.SSS) from a given stringDate in a given dateFormat.
      Parameters:
      stringDate - The string representation of the date (specified in the format dateFormat).
      dateFormat - The the date format in which the string date is specified.
      Returns:
      The internal representation of the stringDate.
      Throws:
      ParseException - - if the sent stringDate cannot be parsed with the given dateFormat.
    • parseDate

      public static Date parseDate(String stringDate, String dateFormat) throws ParseException
      Creates the Date representation of a string date (e.g. in format yyyy-MM-dd HH:mm:ss.SSS) from a given dateFormat.
      Parameters:
      stringDate - The string representation of the date (specified in the format dateFormat).
      dateFormat - The the date format in which the string date is specified.
      Returns:
      The java.util.Date representation of the stringDate.
      Throws:
      ParseException - - if the sent stringDate cannot be parsed with the given dateFormat.
    • createInternalStringDate

      public static String createInternalStringDate(Date inputDate)
      Creates the internal representation of a date (e.g. in format yyyy-MM-dd HH:mm:ss.SSS) from a given inputDate
      Parameters:
      inputDate - The date to be formatted into the internal representation.
      Returns:
      The internal representation of the given inputDate.