
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2017 08:55 PM
We are creating a custom widget that contains the incident resolution time (gr.resolved_at) and incident close time (gr.closed_at) but want to display it in different date time format (like July 11, 2017 12:35PM) instead of the system default 2017-07-11 12:35:00 (note that we only want to do this on this widget so changing the system default date/time format is not an option.
We need to adjust the time shown depending on user time zone as well.
Solved! Go to Solution.
- Labels:
-
Incident Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-11-2017 08:15 PM
Hello everyone! Thanks for all the help, we are now able to implement this properly using solution provided by sachin.namjoshi and we added a little adjustment to consider user's time zone.
This code will get the display value instead, which is already on the user's timezone. Although this will not show the correct timezone text, the values show for date and time is properly adjusted to user's timezone:
// Convert Date-Time Format
var temp = new Packages.java.text.SimpleDateFormat("MM/dd/yyyy HH:mm:ss"); //This defines the format of input values, check date-time format of field first
var output = new Packages.java.text.SimpleDateFormat("MMMM dd, yyyy h:mm a"); //Change the date-time format here to what you want
var cdt, rdt, closed, resolved;
cdt = gr.closed_at.getDisplayValue();
cdt = temp.parse(cdt);
closed = output.format(cdt);
rdt = gr.resolved_at.getDisplayValue();
rdt = temp.parse(rdt);
resolved = output.format(rdt);
Now you can just use the variables resolved and closed anywhere you want to display the date/time formatted to the format you setup.
Sample input: 07/12/2017 21:30:00
Sample output: July 12, 2017 9:30 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2017 09:11 PM
Hi Jim,
How is the date being set in the field you're referring to and what method(s) are you using to display it in both the catalog item and portal?
Typically UTC is the default format (yyyy-MM-dd HH:mm:ss).
I would suggest looking at the following links with regards to format and setting/getting values.
http://wiki.servicenow.com/index.php?title=Using_Date_and_Time_Fields#Date_Format
GlideDateTime - ServiceNow Wiki
Please mark Correct or helpful.
Regards,
Parvinder

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2017 09:16 PM
We are calling the fields on the server-side script using gr.resolved_at and gr.closed_at. Can you provide a sample code that can convert the date/time values of those field to something like "July 11, 2017 12:35PM"

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2017 10:10 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-11-2017 12:48 AM
Hello, we tried this and it works but it shows time in GMT regardless of user timezone preference - do you have an idea of how we can take into account the user's timezone (or system timezone)