Time Functions
Use time functions to return the current time or to transform datetime data.
You can replace any datetime argument with an expression that evaluates to a datetime value. You cannot replace a datetime argument with a datetime literal.
You can replace any long or string argument with a literal or an expression that evaluates to the argument. String literals must be enclosed in single or double quotation marks.
Not valid in Data Collector Edge pipelines. Do not use time functions in Data Collector Edge pipelines.
The expression language provides the following time functions:
- time:createDateFromStringTZ(<string>, <time zone>, <date format>)
- Creates a Date object based on a datetime in a String field and using the specified time zone. The datetime string should not include the time zone.
- time:dateTimeToMilliseconds(<Date object>)
-
Converts a Date object to an epoch or UNIX time in milliseconds.
For example, the following expression converts the current time to epoch or UNIX time in seconds, and then multiplies the value by 1000 to convert the value to milliseconds:${time:dateTimeToMilliseconds(time:now())}
Return type: Long.
- time:dateTimeZoneOffset(<Date object>, <time zone>)
-
Returns the time zone offset in milliseconds for the specified date and time zone. The time zone offset is the difference in hours and minutes from Coordinated Universal Time (UTC).
Uses the following arguments:- Date object - Date object to use.
- time zone - Time zone associated with the Date object.You can use the following time zone formats:
- <area>/<location> - For a list of valid time zones in this format, see https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/timezone.html.
- Numeric time zones with the GMT prefix, such as GMT-0500 or GMT-8:00. Note that numeric-only time zones such as -500 are not supported.
- Short time zone IDs such as EST and CST - These time zones should generally be avoided because they can stand for multiple time zones, e.g. CST stands for both Central Standard Time and China Standard Time.
For example, the following expression returns the time zone offset of the Date object stored in the Date field using the time zone specified in the TZ field:${time:dateTimeZoneOffset(record:value('/Date'), record:value('/TZ'))}
Return type: Long.
- time:extractDateFromString(<string>, <format string>)
-
Extracts a Date object from a String, based on the specified date format.
Uses the following arguments:- string - String to extract the Date object from.
- format string - String that specifies the date format of the data in the <string> argument. For information about creating a date format, see https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html.
- time:extractLongFromDate(<Date object>, <format string>)
- Extracts a long value from a Date object, based on the specified date format.
- time:extractStringFromDate(<Date object>, <format string>)
- Extracts a string value from a Date object based on the specified date format.
- time:extractStringFromDateTZ(<Date object>, <time zone>, <format string>)
- Extracts a string value from a Date object, converting the GMT time in the Date object to the specified date format and time zone. The function adjusts for daylight savings when given the time zone in the appropriate format.
- time:millisecondsToDateTime(<long>)
- Converts an epoch or UNIX time in milliseconds to a Date object.
- time:now()
- Returns the current time of the Data Collector machine as a java.util.Date object.
- time:timeZoneOffset(<time zone>)
-
Returns the time zone offset in milliseconds for the specified time zone. The time zone offset is the difference in hours and minutes from Coordinated Universal Time (UTC).
Uses the following argument:- time zone - Time zone to use.You can use the following time zone formats:
- <area>/<location> - For a list of valid time zones in this format, see https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/timezone.html.
- Numeric time zones with the GMT prefix, such as GMT-0500 or GMT-8:00. Note that numeric-only time zones such as -500 are not supported.
- Short time zone IDs such as EST and CST - These time zones should generally be avoided because they can stand for multiple time zones, e.g. CST stands for both Central Standard Time and China Standard Time.
For example, the following expression returns the time zone offset using the time zone specified in the TZ field:${time:timeZoneOffset(record:value('/TZ'))}
Return type: Long.
- time zone - Time zone to use.
- time:trimDate(<datetime>)
- Trims the date portion of a datetime value by setting the date portion to January 1, 1970.
- time:trimTime(<datetime>)
- Trims the time portion of a datetime value by setting the time portion to 00:00:00.