Need to Change my Date to UTC Format

Aswartha
Mega Contributor

Hi Everyone,

I am integrating Servicenow to IGC(Which is 3rd party Application) through Servicenow Workflow.

i am able to pass all the field values into IGC,but due_date value is not passing to IGC(showing error:Unable to parse the Date Format)

Date format in IGC is UTC, so in Run script how can i changes my Date format to UTC.

If anyone knows, please let me know, i need to submit this task ASAP

Thank you,

Aswartha

 

12 REPLIES 12

Omkar Mone
Mega Sage

Hi 

Try adding this into the code before you pass it - 

 

var temp = new Packages.java.text.SimpleDateFormat("MM/dd/yyyy HH:mm:ss");// the format that you want to send.

var ddt;

ddt = temp.parse();

and pass this ddt to your setStringParameter.

 

Regards

Omkar Mone

 

asifnoor
Kilo Patron

Hi Awartha,

You can convert the date to another timezone like this.

var gdt = new GlideDateTime();
var tz = Packages.java.util.TimeZone.getTimeZone("GMT"); //sets to GMT
gdt.setTZ(tz);

gdt.setValue(your_date);//this will convert to the GMT.
gs.print(gdt.getDisplayValue());

Mark the comment as a correct answer and also helpful if it helps.

Hi Asif, Thank you very much for Responding...

 

var dueDate1 = current.variables.due_date;

var gdt = new GlideDateTime();
var tz = Packages.java.util.TimeZone.getTimeZone("UTC"); //sets to GMT
gdt.setTZ(tz);

var date1 = gdt.setValue(dueDate1);//this will convert to the GMT.
//gs.print(gdt.getDisplayValue());

try {
var r = new sn_ws.RESTMessageV2('Creating Terms in IGC with Snow workflo', 'Post Terms');
r.setStringParameterNoEscape('custom_Due date',date1 );

 

 

I tried with your code but its not Working, can you please help me to fix this

Thank you 

Aswartha

Try like this. If it does not work, share the output of the log statements that i have added in this code.

var dueDate1 = new GlideDateTime(current.variables.due_date);

var gdt = new GlideDateTime();
var tz = Packages.java.util.TimeZone.getTimeZone("UTC"); //sets to GMT
gdt.setTZ(tz);

var date1 = gdt.setValue(dueDate1);//this will convert to the GMT.
//gs.print(gdt.getDisplayValue());

gs.log(date1);
var tz = gs.getSession().getTimeZone(); 
gs.log (" system time zone is "+tz); 
 

 

Mark the comment as a correct answer and also helpful if it helps.

Hi Asif,

i tried with that one as well, but not getting the result.

Thank you