- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago
how can we convert a time from one timezone to another timezone in both scoped applications and global?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago
function convertDateTimeInGlobal(dateTimeStr, fromTimeZone, toTimeZone) {
var gDate = new GlideDateTime();
gDate.setTimeZone(fromTimeZone);
gDate.setDisplayValue(dateTimeStr);
gDate.setTimeZone(toTimeZone);
return String(gDate.getDisplayValue());
}
function convertDateTimeInScopedAPP(dateTimeStr, fromTimeZone, toTimeZone) {
var scheduleDateinfrTZ = new GlideScheduleDateTime("TZID=" + fromTimeZone + ";" + dateTimeStr);
var dateTimeInternal = scheduleDateinfrTZ;
var schedDateintoTz = new GlideScheduleDateTime(dateTimeInternal);
schedDateintoTz.setTimeZone(toTimeZone);
/* Return the converted date-time as a string */
return String(schedDateintoTz);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago
function convertDateTimeInGlobal(dateTimeStr, fromTimeZone, toTimeZone) {
var gDate = new GlideDateTime();
gDate.setTimeZone(fromTimeZone);
gDate.setDisplayValue(dateTimeStr);
gDate.setTimeZone(toTimeZone);
return String(gDate.getDisplayValue());
}
function convertDateTimeInScopedAPP(dateTimeStr, fromTimeZone, toTimeZone) {
var scheduleDateinfrTZ = new GlideScheduleDateTime("TZID=" + fromTimeZone + ";" + dateTimeStr);
var dateTimeInternal = scheduleDateinfrTZ;
var schedDateintoTz = new GlideScheduleDateTime(dateTimeInternal);
schedDateintoTz.setTimeZone(toTimeZone);
/* Return the converted date-time as a string */
return String(schedDateintoTz);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
I also shared a working solution.
As per new community feature you can mark multiple responses as correct.
If my response helped please mark it correct as well so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago
this will work in both
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());
Global Output
Scoped Output
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
While this solution converts time from the system's local time zone to another, my approach offers greater flexibility by enabling conversions between any two time zones, regardless of the system timezone