How to convert date and time into another time zone in scoped application

Poorna7
Tera Expert

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);

11 REPLIES 11

Taha6
Tera Expert

There is an OOb script include that you can call rmConvertTimeZone 

 

Riya Verma
Kilo Sage
Kilo Sage

HI @Poorna7 ,

 

Hope you are doing great.

You canuse below script to conver to other time zone:

// Assuming 'originalDateTime' is the original date and time in the current time zone
var originalDateTime = new GlideDateTime();

// Set the desired time zone
originalDateTime.setTimeZone('Europe/London'); // you can pass user related dynamic time zone by looking throuh user  record too.

// Retrieve the converted date and time in the new time zone
var convertedDateTime = originalDateTime.getDisplayValueInternal();

// Use the convertedDateTime variable as needed in your application
Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Regards,
Riya Verma