Getting time based on user time zone in scoped application

Eli Guttman
Tera Guru

Hi,

 

We are looking for a way to get a certain date and time in specific time zone using a script. While there are few methods available in the global application, we can't find any in a scoped application.

For example, the setTimeZone function is not available in scoped application:

 

 

var mytime = new GlideDateTime();
mytime.setTimeZone(user.time_zone);

 

 

Is there any parallel option in scoped application?

7 REPLIES 7

Shruti
Mega Sage
Mega Sage

Hi,

There is no parallel option in scoped application but you can create a script include in global scope and try below code

Shruti_0-1706098967211.png

 

Thank you, this is the only solution i found also. It does require to handle some caller restricted access records when you use the script from different scope.

Amit Verma
Kilo Patron
Kilo Patron

Hi @Eli Guttman 

 

You can use setTimeZone as below in a scoped application :

 

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

 

Thanks & Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.

Hi, this solution did not work for me. 

+ gsdt.getGlideDateTime().getDisplayValue()

 

Do not return the expected time according to the time zone i set.