Date time conversion in APIM
search cancel

Date time conversion in APIM

book

Article ID: 105208

calendar_today

Updated On:

Products

STARTER PACK-7 CA Rapid App Security CA API Gateway

Issue/Introduction

This article illustration how to convert the date time to different format.

For example, convert a date with format "13/Jul/2018 10:30" to another format "2018-07-13T10:30:00" 

Environment

Release:
Component: APIGTW

Resolution

The following steps are based on the above example,
1. add custom datetime format 
add following line to the end of cluster wide property datetime.customFormats, 
dd/MMM/yyyy HH:mm 

(NOTE: only the last line doesn't require semicolon";", so you should add ; to the end of the line before last line) 

<Please see attached file for image>

cwp

2. set context variable as datetime 
Date type: Date/Time 
Date Format: dd/MMM/yyyy HH:mm (select the new format from the dropdown list) 
Expression: 13/Jul/2018 10:30 (you can use a string variable instead) 

<Please see attached file for image>

User-added image

3. formatting output 
${<your datetime variable>.yyyy-MM-dd'T'HH:mm:ss} 

<Please see attached file for image>

User-added image

sample policies, (copy the xml and paste to you policy window) 
<?xml version="1.0" encoding="UTF-8"?> 
<wsp:Policy xmlns:L7p="http://www.layer7tech.com/ws/policy" xmlns:wsp="http://schemas.xmlsoap.org/ws/2002/12/policy"> 
<wsp:All wsp:Usage="Required"> 
<L7p:SetVariable> 
<L7p:Base64Expression stringValue="MTMvSnVsLzIwMTggMTA6MzA="/> 
<L7p:VariableToSet stringValue="orgdatestring"/> 
</L7p:SetVariable> 
<L7p:SetVariable> 
<L7p:Base64Expression stringValue="JHtvcmdkYXRlc3RyaW5nfQ=="/> 
<L7p:DataType variableDataType="dateTime"/> 
<L7p:DateFormat stringValue="dd/MMM/yyyy HH:mm"/> 
<L7p:DateOffsetExpression stringValue=""/> 
<L7p:VariableToSet stringValue="newdate"/> 
</L7p:SetVariable> 
<L7p:HardcodedResponse> 
<L7p:Base64ResponseBody stringValue="b2xkIGRhdGU6ICR7b3JnZGF0ZXN0cmluZ30KbmV3IGRhdGU6ICR7bmV3ZGF0ZS55eXl5LU1NLWRkJ1QnSEg6bW06c3N9"/> 
<L7p:ResponseContentType stringValue="text/plain; charset=UTF-8"/> 
</L7p:HardcodedResponse> 
</wsp:All> 
</wsp:Policy> 
 

Additional Information

References, 
https://docops.ca.com/ca-api-gateway/9-3/en/reference/gateway-cluster-properties/miscellaneous-cluster-properties
https://docops.ca.com/ca-api-gateway/9-3/en/reference/context-variables/date-and-time-variables 
https://docops.ca.com/ca-api-gateway/9-3/en/policy-assertions/assertion-palette/policy-logic-assertions/set-context-variable-assertion 
 
As per the 2nd document, for the details of datetime patterns, please refer to, 
https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html 

Attachments

1558699850316000105208_sktwi1f5rjvs16jwi.png get_app
1558699848469000105208_sktwi1f5rjvs16jwh.png get_app
1558699846586000105208_sktwi1f5rjvs16jwg.png get_app