GlideDateTime Conversation. From x timezone to UTC
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2025 01:21 PM
How do I set up a GlideDateTime in Eastern or Central and then return the UTC value?
So 8:00 EST returns 13:00 UTC
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2025 01:53 PM
GlideDateTime will always store the date as UTC. When you retrieve the GlideDateTime you are able to select what time zone you want it converted to. But you never changed how it's stored in UTC.
Here is an example:
*** Script: 2025-02-13 21:53:01
*** Script: 02-13-2025 16:53:01
*** Script: 2025-02-13 21:53:01
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2025 02:05 PM
My requirement is to display business hours of each geo location.
So how do I get 06am EST to return 11:00 UTC.
5:00 CST to return 11 UTC
etc.
If I try what you gave me, it translates from UTC to EST.
var gdt_utc = new GlideDateTime('2025-02-13 06:00:00');
gs.info (gdt_utc); // UTC
gdt_utc.setTimeZone("Canada/Eastern"); // Change time zone
gs.info(gdt_utc.getDisplayValue()); // Show time in Canada/Eastern
gs.info (gdt_utc.getValue()); // Still UTC!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2025 02:26 PM
OK, I think I understand. You have an EST and you want to be able to store it / translate it to UTC so you can display it in multiple time zones.
In the below you create a GlideDateTime object, then you set the time zone to EST, then you set the display value to the time you have (the known time). It has set the time zone object to EST but stores the time as UTC. You can then use the GlideDateTime API to retrieve it different ways, such as how I show you getting central time.
*** Script: 2025-02-13 11:00:00
*** Script: 02-13-2025 06:00:00
*** Script: 02-13-2025 05:00:00

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2025 06:01 PM
Hello,
You can try the below
var gdt_utc = new GlideDateTime(); // current time in UTC
gs.info("UTC: " + gdt_utc); // Output UTC time
// Set time to a specific time (e.g., 06:00 AM EST) in Canada/Eastern
gdt_utc.setValue("2025-02-14 06:00:00"); // Assuming the date is today
gdt_utc.setTimeZone("Canada/Eastern"); // Timezone set to EST
gs.info("EST Time: " + gdt_utc.getDisplayValue()); // Output time in EST
// Convert to UTC
var utc_time = gdt_utc.getValue(); // Get the equivalent UTC time
gs.info("Converted UTC: " + utc_time); // Display converted UTC