Time conversion between different timezones in scoped application
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2025 04:08 AM - edited 07-18-2025 04:44 AM
I have a requirement where I need to write a script to convert CET timezone to a dynamic (user input) timezone value, in a scoped application. I have tried using setTimeZone() but it doesn't seem to be working for scoped applications.
Any response or help on this would be greatly appreciated.
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2025 04:51 AM - edited 07-18-2025 06:40 AM
var usertimezone = "Europe/London";
var ndt = new GlideDateTime();
gs.info("System Time is " + ndt);
var newtimezone = new GlideScheduleDateTime(ndt);
newtimezone.setTimeZone(usertimezone);
gs.info("User set time is " + newtimezone.getGlideDateTime().getDisplayValue());
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2025 05:14 AM
setTimeZone() does work in scoped app
var now = new GlideDateTime();
gs.info("System Time is " + now);
var gsdt = new GlideScheduleDateTime(now);
gsdt.setTimeZone("Europe/London");
gs.info("London time is " + gsdt.getGlideDateTime().getDisplayValue());
If my response helped please mark it correct and close the thread so that it benefits future readers.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2025 05:25 AM
Hi @Anjali Priya
I have some Script Snips that will Help :-
// Step 1: Create GlideDateTime object with current CET time
var gdt = new GlideDateTime(); // current system time (UTC-based)
// Step 2: Get CET offset manually
var cetTZ = java.util.TimeZone.getTimeZone("CET");
var cetOffsetMillis = cetTZ.getOffset(new java.util.Date().getTime());
// Step 3: Add CET offset to UTC
var cetDate = new GlideDateTime();
cetDate.add(cetOffsetMillis / 1000); // converting ms to seconds
// Step 4: Format CET time
var cetJavaDate = cetDate.getDate().getJavaObject();
// Step 5: Convert to user-input timezone
var targetTZ = java.util.TimeZone.getTimeZone(targetTimeZone);
var sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
sdf.setTimeZone(targetTZ);
var userTime = sdf.format(cetJavaDate);
gs.info("Converted CET time to " + targetTimeZone + ": " + userTime);
-----------------------------------
Note: These Script has been Validated and Working !!