How to process ISO8601 Date format

gauravbhandari
Giga Contributor

Hello All,

We have an integration with 3rd part application where are receiving Dates in ISO8601 format. Does anyone know how to process in within servicenow so that time and timezone would remains same. Below are some of the formats we receive:

1)2020-07-31T11:18:31.114Z

2)2020-07-31T11:18:31.161+0000

3)2020-07-31T06:39:51Z

@Ankur Bawiskar @Pradeep Sharma  Could you please support here.

 

Thank You

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Gaurav,

these links should help you

How to convert iso date string (2015-11-18T20:00:00Z) to local time

How to Transform ISO8601 date (yyyy-MM-ddTHH:mm:ssZ) to a date field in a Transform map

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Gaurav,

these links should help you

How to convert iso date string (2015-11-18T20:00:00Z) to local time

How to Transform ISO8601 date (yyyy-MM-ddTHH:mm:ssZ) to a date field in a Transform map

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur,

I have checked both the links already, first link works somehow but 2nd link doesn't process the all the formats. I was looking if any servicenow API available for processing ISO8601 date format.

 

Regards

Gaurav

 

Hitoshi Ozawa
Giga Sage
Giga Sage

To sure where the problem is. Following will convert iso8601 to Javascript datetime.

This can be converted to GlideDateTime.

var x = g_form.getValue("isodatetime");
var d = new Date(x);

 Below is a simple conversion function to convert ISO8601 to yyyy-MM-dd hh:mm:ss

    var MM = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"];
	
    var xx = x.replace(
        /(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):\d{2}(\w{3})/,
        function($0, $1, $2, $3, $4, $5, $6) {
            return $1+"-"+MM[$2-1]+"-"+$3+" "+$4+":"+$5;
        }
    );