The Now Platform® Washington DC release is live. Watch now!
‎06-25-2018 06:46 AM
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.
Solved! Go to Solution.
‎06-27-2018 05:18 AM
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());
‎06-25-2018 06:54 AM
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
‎06-25-2018 07:00 AM
It is not
08:46:18 , the actual time is 14:16:18
‎06-25-2018 07:37 AM
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.
‎06-26-2018 10:22 PM
Could you please help me to convert Todays date in epoch format.