Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

convert date format 1520577092413 to glide date

eashwar
Tera Contributor

Hello,

I am trying to convert date format retrieved from API to Glide Date/Time format

 

API Date - 1520577092413

Has anyone done that before ?

 

Thank you,

Eash

1 ACCEPTED SOLUTION

felladin
Tera Guru

Hello,

Yes, the code is a lot simpler than first suggested:

var epochString = "1520577092413";
var gdt = new GlideDateTime();
gdt.setNumericValue(epochString);
gdt.getDisplayValue();

View solution in original post

3 REPLIES 3

felladin
Tera Guru

Hello,

Yes, the code is a lot simpler than first suggested:

var epochString = "1520577092413";
var gdt = new GlideDateTime();
gdt.setNumericValue(epochString);
gdt.getDisplayValue();

JimmieOdelius
Tera Expert

Hi Eashwar

 

You should be able to use the

 

GlideDateTime mehtod.

 

// Capture the milliseconds from the API you mentioned
var ms = '1520577092413';

// Create a GlideDateTime object
var gdt = new GlideDateTime();
gdt.subtract(gdt.getNumericValue()); // Resets the date to 0 so that we can add the milliseconds to the date
gdt.add(ms); // Adds the milliseconds to the date

var date = gdt.getDisplayValue(); // date should now contain the display value.
var numDate = gdt.getNumericValue(); // numDate should now contain the numeric value.

eashwar
Tera Contributor

Thank you guys