Change Timezone Of Date/Time Field While Transforming

ayush_saxena
Tera Expert

Hello All,

Hope you are doing fine. While performing E bonding Integration between two Service Now instances I encountered with an Time zone issue.

Issue is the other Service Now system runs on CST time zone and uses MM/dd/yyyy hh:mm:ss format where as my system runs on PST Timezone and uses YYYY-DD-MM hh:mm:ss format.

The format can be converted easily while Transforming but the timezone remains CST.

I tried below script and getting Answer   gdt.setTZ(tz) as undefined.

var tz = gs.getSession().getTimeZone();

var val = source.start_date;

var gdt = new GlideDateTime(val);

var ntZ= gdt.setTZ(tz);

gs.log(' Answer   gdt.setTZ(tz) == ' + ntZ);

Is it I am not utilizing it efficiently? Please assist

Thanks and Regards,

Ayush Saxena

5 REPLIES 5

sumeet_n
Kilo Guru

'gdt.setTZ(tz)' only sets the time zone and doesnt return anything.



Use 'gdt.getValue()' to get the modified time value.



Let me know if this helps.


Basically try this:




var tz = gs.getSession().getTimeZone();


var val = source.start_date;


var gdt = new GlideDateTime(val);


gdt.setTZ(tz);


gs.log(' Answer     ' + gdt.getValue());


It is always returning "2016-04-07 13:45:39"


Can you confirm is timezone has been set correctly? tz has the expected timezone?



var tz = gs.getSession().getTimeZone();


gs.log(tz);


var val = source.start_date;


var gdt = new GlideDateTime(val);


gdt.setTZ(tz);


gs.log(' Answer     ' + gdt.getValue());