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.

tiagomacul
Giga Sage

.

 Function

function convertDateToEpoch(vDate)
{
   epoch = '';
   vDateTmp = new GlideDateTime(vDate).getNumericValue() / 1000;
   epoch = (Math.round((vDateTmp *Math.pow(10,0)).toFixed(0-1))/Math.pow(10,0)).toFixed(0);
   return epoch;
}

 

How to use

 

var ObjDate = new GlideDateTime();   
gs.log(ObjDate);
gs.log(convertDateToEpoch(ObjDate));

 

.

*** Script: 2019-01-18 01:14:08
*** Script: 1547774050

https://www.epochconverter.com/

Know-More-Now-Logo.jpg

Script Summary

 

Was useful, please leave your feedback!

Comments
Dianah
Tera Contributor

long epoch = new java.text.SimpleDateFormat("MM/dd/yyyy HH:mm:ss").parse("01/01/1970 01:00:00").getTime() / 1000; Timestamp in seconds, remove '/1000' for milliseconds. date +%s -d"Jan 1, 1980 00:00:01" Replace '-d' with '-ud' to input in GMT/UTC time.

 

Regards,

Diana

gay3
Tera Explorer

Hi tiagomacul , 

 

This function is not working. Getting "0"value as an output for below line.

vDateTmp = new GlideDateTime(vDate).getNumericValue() / 1000;

 

Version history
Last update:
‎01-17-2019 05:20 PM
Updated by: