How to output the current time in seconds (epoch time) on the gateway
search cancel

How to output the current time in seconds (epoch time) on the gateway


Article ID: 5151


Updated On:


CA API Gateway


How can I output the current time in seconds (epoch time) every time a service is engaged?


Component: APIGTW


To get the time output from your Gateway to the service please do the following

Prerequisites: An existing service to add assertions to


  1. Go to the Policy Manager and Login
  2. Under Assertions (on Top Left) there is a Search Bar, put in “Set Context Variable” Drag the “Set Context Variable” Assertion to the right of the screen and the Context Variable Properties window will open up.


<Please see attached file for image>

src="/servlet/servlet.FileDownload?file=0150c000004AKAPAA4" alt="SetTimeDate1.png" width="329" height="502">

      3. Give it a VariableName: Example: TimeAbsTest

Data Type: Message

Format: from the drop down menu select the following: Text/Plain; charset=utf-8

Expression: ${gateway.time.seconds}

<Please see attached file for image>

src="/servlet/servlet.FileDownload?file=0150c000004AKAQAA4" alt="SetTimeDate1a.png" width="517" height="379">

       4. Add another assertion called “Return Template Response to Requester”

Change Response Content Type: text/plain; charset=UTF-8

Response Body: “${TimeAbsTest}”


<Please see attached file for image>

src="/servlet/servlet.FileDownload?file=0150c000004AKASAA4" alt="SetTimeDate3.png" width="556" height="379">

5. Once you have done this you can Save and activate your service and then go to the service URL


The ouput should be like the following (time in seconds)

<Please see attached file for image>

src="/servlet/servlet.FileDownload?file=0150c000004AKARAA4" alt="SetTimeDate2a.png" width="383" height="128">

 You should be able to see the output of the time stamp on the service if you see an error you can add the assertion “Customize SOAP Fault Response as Full Detail” to give you more details on what is causing the error.

Additional Information

Variables Descriptions
${gateway.time.<suffix>} Returns the current time on the Gateway; suffix is optional.
${request.time.<suffix>} Returns the time the request was received; suffix is optional.
There are a variety of suffixes that you can append (to both the built-in variables or to custom date/time variables) to modify or reformat the time that is returned. These suffixes are summarized in the following table.
When a date/time variable is used without a suffix, the time value returned is in ISO 8601 format, in the UTC (Coordinated Universal Time) time zone

Suffix Description
.local Returns the value in local time.
.utc Returns the value in UTC time. This is the same as using no suffix at all.
.<SimpleDateFormat> Returns the value in a specified format. You can append a format to the above suffixes (or on its own) to create unstructured suffixes using symbols from java.text.SimpleDateFormat. Examples:
For more information on the SimpleDateFormat, see

.millis Access a timestamp in milliseconds for the variable. This suffix must appear directly after the variable (for example, ${mydate.millis}).
.seconds Access a second timestamp for the variable. This suffix must appear directly after the variable (for example, ${gateway.time.seconds}).
.<timezone>.<formatting> Returns the value in the specified time zone (case insensitive) with optional custom formatting.

${myvar.BST} - value of myvar is in British Standard Time formatted as an ISO 8601 string
${request.time.BST.hh:mm:ss} - request is in British Standard Time with specified custom formatting
Time zone suffixes are all those supported by the java.util.TimeZone.getAvailableIDs() utility.
.<offset> Returns the value in the local time offset by the specified <offset> value. Examples of valid values:
The following are examples of invalid <offset> values:
.<StructuredFormat> Returns the value in any of the following structured formats:
• .iso8601 - yyyy-MM-ddTHH:mm:ss.SSSX
• .rfc1123 - E, dd MM yyyy hh:mm:ss Z
• .rfc850 - EEEE, dd-MM-yy hh:mm:ss Z
• .asctime - E MMM d hh:mm:ss yyyy
These suffixes can be used directly after the variable name or after a timezone:
${myvar.BST.rfc1123} - BST date string formatted according to rfc1123
${myvar.rfc1123} - Date string formatted according to GMT (Zulu) time zone.



1558707290165000005151_sktwi1f5rjvs16qmy.png get_app
1558707285938000005151_sktwi1f5rjvs16qmw.png get_app