Time conversion to 24hr format
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-28-2020 07:15 AM
Hi,
I was asked to write a script to convert CST time to GMT time. I developed that successfully but now i am asked to convert 12 hour format to 24 hour format in same script. Can you please suggest what changes i can do to achieve this in below script.
var tz = Packages.java.util.TimeZone.getTimeZone("GMT");
var sd = new GlideDateTime();
sd.setTZ(tz);
sd.setValue(current.start_date);
variable.inputs.planned_start_date = sd.getDisplayValue().toString();
var ed = new GlideDateTime();
ed.setTZ(tz);
ed.setValue(current.end_date);
variable.inputs.planned_end_date = ed.getDisplayValue().toString();
ServiceNow Community Rising Star 2022/2023
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-14-2020 12:55 AM
GlideDateTime values are already stored in 24-hour format.
what is the exact requirement here?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-14-2020 01:09 AM
We have B2B with other instance.
In change module we are passing values for Planned start date and Planned end date in our instance. Our instance is in 12hr format but the other instance is in 24hr format.
So whenever anyone passes the values from our side it goes in 12hr format and timing is not updated correctly on other side.
ServiceNow Community Rising Star 2022/2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-14-2020 02:05 AM
just to inform the Package call won't work in scope application.
please share what value you are receiving and what value you want to get from that?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-14-2020 02:10 AM
i didn't understand what do you mean by saying that package call won't work in scope application. The code earlier was working fine where it just converted CST time to GMT time before sending the transaction to other instance.
Here i the value in start_date variable is stored in 12Hr format. like- 2020-09-17 08:00:00 PM, in CST time.
I want it to be in GMT time zone and in 24hr format and this will be passed in planned_start_date variable.
ServiceNow Community Rising Star 2022/2023

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-16-2020 04:00 AM
If you're not getting an error like below, you're probably not using scope.
java.lang.SecurityException: Use of Packages calls is not permitted in scoped applications