Change Timezone Of Date/Time Field While Transforming

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-13-2016 12:09 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-13-2016 12:42 PM
'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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-13-2016 12:43 PM
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());

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-13-2016 03:03 PM
It is always returning "2016-04-07 13:45:39"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-13-2016 10:17 PM
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());