Facing issues in Converting JSON datetime field into ServiceNow format
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2022 01:11 PM
Hello Geeks,
I am calling in a API and receiving a response and I am trying to push the values into an import set using a transform map.
Below are the fields that I am receiving and trying to convert them into ServiceNow datetime format. (dd-MM-yyyy HH:mm:ss) but not able to convert them.
"Start Time": "Apr 13, 2022, 08:00:25 PM"
"End Time": "Apr 18, 2022, 06:57:18 AM"
Please help me out in how to convert them.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2022 02:13 PM
Hello Aditya,
Check this example:
var json_obj = {"start_time": "Apr 13, 2022, 08:00:25 PM"};
var date = new GlideDateTime();
date.setDisplayValue(json_obj.start_time, "MMM dd, yyyy, hh:mm:ss a");
gs.print(date.getDisplayValue()); //displays according to the timezone and date format of your user
I think this is exactly what you need!
Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!
Best Regards,
Filipe Cruz
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2022 10:23 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2022 01:12 AM
Hello Aditya,
Here is an example of converting GMT to Canada timezone.
Use this example to convert to your own timezone (EST in this case):
//converting GMT to Canada/Eastern
var tz = Packages.java.util.TimeZone.getTimeZone("Canada/Eastern");
var date = new GlideDateTime();
date.setTZ(tz);
Hope this helps!
Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!
Best Regards,
Filipe Cruz
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2022 11:25 AM
Hello Filip,
I am using the code as below.
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
var date = new GlideDateTime();
var tz = Packages.java.util.TimeZone.getTimeZone("Canada/Eastern");
date.setDisplayValue(source.u_start_time, "MMM dd, yyyy, hh:mm:ss a");
date.setTZ(tz);
target.u_backup_start = date.getDisplayValue(); // return the value to be put into the target field
var date1 = new GlideDateTime();
var tz1 = Packages.java.util.TimeZone.getTimeZone("Canada/Eastern");
date1.setDisplayValue(source.u_end_time, "MMM dd, yyyy, hh:mm:ss a");
date1.setTZ(tz1);
target.u_backup_end = date1.getDisplayValue(); // return the value to be put into the target field
})(source, map, log, target);
The source fields that I am receiving are in IST. But when I use the above logic it still shows the same datetime which I am receiving which means it's not converting it into EST.