Liquid Template unable to parse date correctly with time zone offset

Sumit Gaur 235 Reputation points
2024-09-23T10:11:52.9866667+00:00

Hi Team,

we are using set-body policy with liquid template to transform our API request to backend soap service request. in the request we have a string field for creation date in which the datetime format comes like this : 2024-09-20T10:47:35.085884-04:00 with a time zone offset in respect to UTC. when we map this field as is to our liquid template the liquid template change the datetime format to 9/20/2024 2:47:35 PM where it removes the offset and gives us the UTC time. i have tried to use the Date filter as mentioned in the msdn documents, but it also not able to preserve the offset value and though format the date correctly as it comes in input but changes the time to UTC time with an offset of +00.00, e.g. 2024-09-20T14:47:35.085+00:00, the filter i use in this case was as shown below, how can i preserve the date in same format as it is coming in the original request.

 Date: "yyyy-MM-ddTHH:mm:ss.fffzzz"
Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
2,130 questions
{count} votes

1 answer

Sort by: Most helpful
  1. LeelaRajeshSayana-MSFT 15,396 Reputation points Microsoft Employee
    2024-09-24T20:58:56.47+00:00

    Hi @Sumit Gaur Can you please add the setting parse-date="false" within your like this

    <set-body parse-date="false"> //get your date object </set-body>
    

    This setting should prevent the dates from getting parsed to System.DateTime (mm/dd/yyyy hh:mm:ss) format and should retain the same date value. Please let us know if you encounter the same behavior even after applying this setting.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.