From 7d6603591f3c1c1df63b2b1eb28989398c0cce76 Mon Sep 17 00:00:00 2001 From: Code with bhav <92107107+bhavyaa30@users.noreply.github.com> Date: Sun, 5 Oct 2025 20:18:56 +0530 Subject: [PATCH 1/2] script.js --- .../Convert UTC to Local Time/script.js | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Core ServiceNow APIs/GlideDateTime/Convert UTC to Local Time/script.js diff --git a/Core ServiceNow APIs/GlideDateTime/Convert UTC to Local Time/script.js b/Core ServiceNow APIs/GlideDateTime/Convert UTC to Local Time/script.js new file mode 100644 index 0000000000..ae875178a8 --- /dev/null +++ b/Core ServiceNow APIs/GlideDateTime/Convert UTC to Local Time/script.js @@ -0,0 +1,21 @@ +(function() { + var gr = new GlideRecord('incident'); + gr.addQuery('active', true); + gr.orderByDesc('opened_at'); + gr.setLimit(1); // Example: take the latest active incident + gr.query(); + + if (gr.next()) { + // GlideDateTime object from UTC field + var utcDateTime = gr.opened_at; + + // Convert to user's local time zone + var localTime = new GlideDateTime(utcDateTime); + var displayValue = localTime.getDisplayValue(); // Returns local time in user's timezone + + gs.info('UTC Time: ' + utcDateTime); + gs.info('Local Time: ' + displayValue); + } else { + gs.info('No active incidents found.'); + } +})(); From 89032ec3fbd21ad80f3078e05865739cc376020f Mon Sep 17 00:00:00 2001 From: Code with bhav <92107107+bhavyaa30@users.noreply.github.com> Date: Sun, 5 Oct 2025 20:19:46 +0530 Subject: [PATCH 2/2] readme.md --- .../GlideDateTime/Convert UTC to Local Time/readme.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 Core ServiceNow APIs/GlideDateTime/Convert UTC to Local Time/readme.md diff --git a/Core ServiceNow APIs/GlideDateTime/Convert UTC to Local Time/readme.md b/Core ServiceNow APIs/GlideDateTime/Convert UTC to Local Time/readme.md new file mode 100644 index 0000000000..9a027de385 --- /dev/null +++ b/Core ServiceNow APIs/GlideDateTime/Convert UTC to Local Time/readme.md @@ -0,0 +1,7 @@ +## Overview +This script converts a UTC date/time field in ServiceNow to the **user's local time** using **GlideDateTime**. +Useful for notifications, reports, dashboards, or any situation where users need **localized timestamps**. + +## Table and Field Example +- **Table:** `incident` +- **Field:** `opened_at` (stored in UTC)