The Now Platform® Washington DC release is live. Watch now!

Help
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Epoc Date conversion

monu1
Giga Contributor

Hello Everyone,

In our project , ticket is created through Integration with Remedy.

So they are sending Planned Start And End Date of Change in EPOC format.

I have converted in Servicenow in yyyy/mm/dd HH:mm:ss format. But the time is not working Perfectly

 

Code:

var timestamp = 1536914778;

var dt = new Date(timestamp*1000);
var year = dt.getFullYear();
var month = dt.getMonth() + 1;
var day = dt.getDate();
var hours = dt.getHours();
var minutes = dt.getMinutes();
var seconds = dt.getSeconds();

document.write(year+"-"+month+"-"+day+" " +hours+":"+minutes+":"+seconds);

 

Output: 

2018-9-14 1:46:18(servicenow)
2018-9-14 14:16:18(javascript console)

It should come as Javascript console but in servicenow the timeing is coming as 1 instead of 14.

Could anyone tell me why the time is not working correctly in Servicenow.
1 ACCEPTED SOLUTION

johnnyd54
Giga Expert

Epoch is just the amount of time that has passed since a certain point in time. Service-Now, Unix, and many others you'll see use Jan 1, 1970 as the point of time. So to get the amount of ms from that point of time, use this:

 

var epoch = new GlideDateTime().getNumericValue();

 

This gives you the value in ms..

 

Now if you take that value and put it in

var gdt = new GlideDateTime();
gdt.setNumericValue(epoch);
gs.print(gdt);

It will give you the current date/time in UTC time.

 

Local time you can use gs.print(gdt.getDisplayValue());

 

View solution in original post

5 REPLIES 5

johnnyd54
Giga Expert

If epoc is date/time in milliseconds, you could do something like this:

ar gdt = new GlideDateTime();
gdt.setNumericValue(1536914778000);
gs.print(gdt);

2018-09-14 08:46:18

 

monu1
Giga Contributor

It is not 

08:46:18 , the actual time is 14:16:18

Yeah the 8:46 is the time in UTC time. What time zone are you? Depending on where you are, the local time will be different.

monu1
Giga Contributor

Could you please help me to convert Todays date in epoch format.