Date time conversion in APIM
search cancel

Date time conversion in APIM

book

Article ID: 105208

calendar_today

Updated On:

Products

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

All supported versions of the API Gateway

Resolution

The following steps are based on the following 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) 



2. set context variable 
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) 


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


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://techdocs.broadcom.com/us/en/ca-enterprise-software/layer7-api-management/api-gateway/10-1/reference/gateway-cluster-properties/miscellaneous-cluster-properties.html
https://techdocs.broadcom.com/us/en/ca-enterprise-software/layer7-api-management/api-gateway/10-1/reference/context-variables/date-and-time-variables.html
https://techdocs.broadcom.com/us/en/ca-enterprise-software/layer7-api-management/api-gateway/10-1/policy-assertions/assertion-palette/policy-logic-assertions/set-context-variable-assertion.html 
 
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