GlideDate to ISO 8601

as i start this article, i have a confusion to say . i really hate working with date:).however,if you are dealing a lot with custom integration you probably notice that working with date in ServiceNow is more a complex.
in some cases, like for example sending date in SOAP Message, you need to follow ISO-8601 standard . The example below,shows how to convert GlideDate to  ISO 8601 with two different format


function ConvertToISO8601(passdate){

// java class concrete class for formatting and parsing dates in a locale-sensitive manner
var SimpleDateFormat =;
var TimeZone =;

// java class lets you manipulate dates in a system independent way
var Date =;

var gdt =passdate.getGlideObject();

//convert the date to milliseconds
var date = new Date(gdt.getNumericValue());
var format = “yyyy-MM-dd’T’HH:mm:ssZ”;

// set the time zone here
tz = TimeZone.getTimeZone(‘US/Mountain’);
var f = new SimpleDateFormat(format);

var formatted = f.format(date); //  return f.format(date) would be in this format 2014-09-02T11:28:56+00:00
return formatted.substring(0, 19) + ‘Z’; //would be in this format  2014-09-02T11:28:56Z

Leave a Reply

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

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

Facebook photo

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

Connecting to %s