Date Manipulation
format
Description: Formats a number as a date/time according to the format specified by the argument. The argument must be a String that is a valid Java SimpleDateFormat format. The Subject is expected to be a Number that represents the number of milliseconds since Midnight GMT on January 1, 1970. The number will be evaluated using the local time zone unless specified in the second optional argument.
Subject Type: Number
Arguments:
-
format : The format to use in the Java SimpleDateFormat syntax
-
time zone : Optional argument that specifies the time zone to use (in the Java TimeZone syntax)
Return Type: String
Examples: If the attribute "time" has the value "1420058163264", then the following Expressions will yield the following results:
Expression | Value |
---|---|
${time:format("yyyy/MM/dd
HH:mm:ss.SSS'Z'", "GMT")} |
2014/12/31 20:36:03.264Z |
|
2014/12/31 12:36:03.264Z |
${time:format("yyyy/MM/dd
HH:mm:ss.SSS'Z'", "Asia/Tokyo")} |
2015/01/01 05:36:03.264Z |
${time:format("yyyy/MM/dd",
"GMT")} |
2014/12/31 |
${time:format("HH:mm:ss.SSS'Z'",
"GMT")} |
20:36:03.264Z |
${time:format("yyyy",
"GMT")} |
2014 |
toDate
Description: Converts a String into a Date data type, based on the format specified by the argument. The argument must be a String that is a valid Java SimpleDateFormat syntax. The Subject is expected to be a String that is formatted according the argument. The date will be evaluated using the local time zone unless specified in the second optional argument.
Subject Type: String
Arguments:
-
format : The current format to use when parsing the Subject, in the Java SimpleDateFormat syntax.
-
time zone : Optional argument that specifies the time zone to use when parsing the Subject, in the Java TimeZone syntax.
Return Type: Date
Examples: If the attribute "year" has the value "2014" and the attribute "time"
has the value "2014/12/31 15:36:03.264Z", then the Expression
${year:toDate('yyyy', 'GMT')}
will return a Date data type with a
value representing Midnight GMT on January 1, 2014. The Expression
${time:toDate("yyyy/MM/dd HH:mm:ss.SSS’Z'", "GMT")}
will result in a
Date data type for 15:36:03.264 GMT on December 31, 2014.
Often, this function is used in conjunction with the format function to change the format of a
date/time. For example, if the attribute "date" has the value "12-24-2014" and we want
to change the format to "2014/12/24", we can do so by chaining together the two
functions: ${date:toDate('MM-dd-yyyy'):format('yyyy/MM/dd')}
.
now
Description: Returns the current date and time as a Date data type object.
Subject Type: No Subject
Arguments: No arguments
Return Type: Date
Examples: We can get the current date and time as a Date data type by using the
now
function: ${now()}
. As an example, on Wednesday
December 31st 2014 at 36 minutes after 3pm and 36.123 seconds EST
${now()}
would be evaluated to be a Date type representing that
time. Since whole Expression Language expressions can only return Strings it would
formatted as Wed Dec 31 15:36:03 EST 2014
when the expression
completes.
Utilizing the toNumber method, now
can
provide the current date and time as the number of milliseconds since Midnight GMT on
January 1, 1970. For instance, if instead of executing ${now()}
in the
previous example ${now():toNumber()}
was run then it would output
1453843201123
. This method provides millisecond-level precision and
provides the ability to manipulate the value.
Expression | Value |
---|---|
${now()} |
A Date type representing the current date and time to the nearest millisecond |
${now():toNumber()} |
The number of milliseconds since midnight GMT Jan
1, 1970 (1453843201123 , for example) |
${now():toNumber():minus(86400000) |
A number presenting the time 24 hours ago |
${now():format('yyyy')} |
The current year |
${now():toNumber():minus(86400000):format('E')} |
The day of the week that was yesterday, as a
3-letter abbreviation (For example, Wed ) |