Package com.tridion.util
Class TimeUtils
java.lang.Object
com.tridion.util.TimeUtils
Contains utilities related to handling of time values.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThis is the internal date format used in the database. -
Method Summary
Modifier and TypeMethodDescriptionstatic longconvertTimeToMs(int value, String units) Converts a time value to milliseconds in a rather inflexible manner.static longconvertTimeToMs(String text) Converts a time value to milliseconds.static StringcreateInternalStringDate(String stringDate, String dateFormat) Creates the internal representation of a date (e.g.static StringcreateInternalStringDate(Date inputDate) Creates the internal representation of a date (e.g.static DateFormatCreates a formatter for generating UTC DateTime strings.static DateFormatGet Raw date format for dates in format MMM dd, yyyy HH:mm:ss a like (Dec 29, 2016 9:25:31 AM).static DateCreates the Date representation of a string date (e.g.
-
Field Details
-
DATE_FORMAT
This is the internal date format used in the database.- See Also:
-
-
Method Details
-
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 thatDateFormats are not synchronized. It is recommended to create separate format instances for each thread.- Returns:
- The formatter.
-
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
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
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
-1if 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
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
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.
-