Convert date to UNIX time stamp

lets start off with getting to know what is Unix time stamp.
UNIX time stamp is a way to track time in seconds, the tracking start from 01-01-1970.
in ServiceNow,sometimes we are in need for this kind of format especially in integration tasks . the function below would make it easy to convert glide date to UNIX time stamp 🙂
function ConvertToUnix(passdate){
// Import Java Date Class
var Date = Packages.java.util.Date;
//get glide date object
var gdt =passdate.getGlideObject();
// create instance from date object . pass date as milliseconds . getNumericValue() would do the job
var date = new Date(gdt.getNumericValue());
// getTime converts date to unix time stamp
var diff = date.getTime();
// return unix time stamp
return diff;
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s