Convert time in ISO 8601 format to UTC

Hi,
Response payload of one of the APIs I’m working on contains LastUpdate date. When I make an API call through postman, date is returned in UTC format(2023-11-22T17:46:55.3288086+00:00)

However, when same call is made through WebAPI Activity on UiPath it returns in ISO8601 format (2023-11-22T11:46:55.3288086-06:00)

My workflow involves in sending the response with these date values for an update (POST). And it is failing as the POST method is expecting UTC format. How do I convert this in UiPath? Using C#.

Thanks in advance!

Hi @Sarat_Y

Try this

 iso8601Date = "2023-11-22T11:46:55.3288086-06:00";
dateTimeOffset = DateTimeOffset.Parse(iso8601Date, null, DateTimeStyles.RoundtripKind);
utcDateTime = dateTimeOffset.UtcDateTime;

utcFormat = utcDateTime.ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ");

iso8601Date is of DataType System.String
dateTimeOffset is of DataType DateTimeOffset
utcDateTime is of DataType System.DateTime
utcFormat is of DataType System.string

Check out this thread. It might help you

Hope it helps

Hi,

FYI, another approach:

strDate = "2023-11-22T11:46:55.3288086-06:00"

Then

DateTime.Parse(strDate).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffffffK")

If you need +00:00 instead of Z, the following will work

DateTime.Parse(strDate).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffffff+00:00")

Sample
Sample20231220-1CS.zip (2.4 KB)

Regards,

1 Like

Thank you. It helped.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.