How to convert date and time into another time zone in scoped application
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2020 01:25 AM
In below script include we are getting the location time zone and date of the location to be in office . Currently My Requirement is to convert the both location date(ld) and current datetime (nowDT) into location time zone i.e. getLOcationTimeZone . Both ld and now DT are in GMT time zone.
var getDate = Class.create();
getDate.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getDateInfo: function() {
var getLocation = current.variables.office_location.time_zone; // Get the LOcation Time Zone
var locationDate = this.getParameter('sysparm_user_sysId'); // Get the Date of the Location on which the user wants to be in office
var ld = new GlideDateTime(locationDate); // GMT Time Zone
var nowDT = new GlideDateTime(); //GMT Time Zone
var dur = GlideDateTime.subtract(nowDT,ld);
var duration = dur.getNumericValue();
var durationSeconds = (duration/1000);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2020 01:31 AM
Hi Akansha,
Did you tried using getUserTimezone() ?
https://developer.servicenow.com/dev.do#!/reference/api/paris/server/no-namespace/GlideCalendarDateTimeAPI#GCDT-getUserTimeZone?navFilter=timezone
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2020 01:35 AM
getUserTimezone() retrieves the time zone for the current user session.
But I want the time zone to be converted into location time zone.
The user time zone and location timezone can be different.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2021 09:19 AM
try below
var time = new GlideDateTime(); // Display date retrieved
gs.print('GMT Time: '+time); // Set timezone
var tz = Packages.java.util.TimeZone.getTimeZone("America/New_York");
//var tz = Packages.java.util.TimeZone.getTimeZone("IST");
time.setTZ(tz); // Get offset of timezone set above
var timeZoneOffSet = time.getTZOffset(); // Add offset to current time
time.setNumericValue(time.getNumericValue() + timeZoneOffSet); // Print date/time in desired timezone
gs.print('Eastern time: '+time);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2021 07:40 AM
Hi
I'm not the OP, but have same question.
In a Scoped Application I get
"JavaException: java.lang.SecurityException: Use of Packages calls is not permitted in scoped applications"