- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-06-2020 06:26 AM
Hi,
I am trying to get the time difference between the current time/Date and end_time (time/date) based on Time zone provided by the user in SCOPED application.
To achieve this I need to first get the current time/date in the time zone provided by the user. Please help me with this.
Thanks in Advance.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-06-2020 04:36 PM
Hi,
You would need to add a timezone offset to get the date time in a specific timezone.
This can be achieved in global scope using package calls or using setTZ method for a logged in users session object.
However, there is no api accessible in scoped apps. You may look at the moment.js opensource library.
//below piece of code will give you the timezone offset w.r.t UTC...
var tZSetOnVarOffSet = moment.tz(moment.utc(), tZSetOnVar).utcOffset();
//-- you can add the timezone offset to your current date time to fetch the date time in another timezone
I am adding the link of your previous question as well, as the solution for both are similar. You can follow the detailed script in the below question answer -
Regards,
Anirban

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-06-2020 06:29 AM
Hi Divya,
This is for current time:
var tz = "<Timezone value> i.e.Canada/Eastern";
//var tz = Packages.java.util.TimeZone.getTimeZone("Canada/Eastern");
var gDT = new GlideDateTime();
gDT.setTZ(tz);
var abc = gDT.getDisplayValue();
For a field time use:
var tz = "<Timezone value> i.e.Canada/Eastern";
var gDT = new GlideDateTime(current.<field_name>);
gDT.setTZ(tz);
var abc = gDT.getDisplayValue();
Check this link for reference: https://community.servicenow.com/community?id=community_question&sys_id=4714cfe5dbd8dbc01dcaf3231f96...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-06-2020 06:35 AM
This method does not work as this is a scoped application

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-06-2020 06:58 AM
Interesting, this is documented but the example doesn't work:

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-06-2020 04:36 PM
Hi,
You would need to add a timezone offset to get the date time in a specific timezone.
This can be achieved in global scope using package calls or using setTZ method for a logged in users session object.
However, there is no api accessible in scoped apps. You may look at the moment.js opensource library.
//below piece of code will give you the timezone offset w.r.t UTC...
var tZSetOnVarOffSet = moment.tz(moment.utc(), tZSetOnVar).utcOffset();
//-- you can add the timezone offset to your current date time to fetch the date time in another timezone
I am adding the link of your previous question as well, as the solution for both are similar. You can follow the detailed script in the below question answer -
Regards,
Anirban