How to get a time of the particular time zone by using script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-20-2021 08:46 PM
Hi
Can anyone let me know how to get a time of the particular time zone using the script?
I have a custom field which stores time zone name, I want to know the current time of that time zone by using script?
One more question, is there any possibility to know the current time happening in any time zone?
Eg: If the time is 11 AM can we find in which time zone time is 11AM how to find the time zone name?
Assistance on this is highly appreciated.
Thanks,
Ksnow
- Labels:
-
Scripting and Coding
-
Team Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-20-2021 09:16 PM
Hi,
You can convert a date/time from GMT to particular timezone and print it
refer below link for help
Time Conversion Based upon Timezone
One more question, is there any possibility to know the current time happening in any time zone? -> it depends on the logged in user's timezone or the timezone preference in the system settings
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-20-2021 11:59 PM
Thank you for your response.
My requirement is below.
It's related to SLA subject and it's custom implementation. Time zones and schedules are involved in this subject. I want to calculate the Acknowledge duration, usually calculation is from incident opened_at to incident is assigned to someone(assigned to field filled).
I have defined time zone and schedule in the each business service that will be reflected in the incident form, based on this time zone and schedule acknowledge duration should be calculated.
Here is the example:
If the incident is opened at 5.45 AM in the Asia/Kolkata time zone. The defined schedule is 9am-6pm with time zone Asia/Kolkata
The supporter(Asia/Kolkata time zone user) who is going to work on the incident assigned the incident to himself at 8 AM in the morning, Acknowledge duration should be zero/null because it should consider from 9am-6pm within the Asia/Kolkata time zone.
I am using the below script to get the job done.
var gdt = new GlideDateTime(current.getDisplayValue("opened_at")); //opened_at time
var nowUTC = new GlideDateTime(gs.nowDateTime()); // current time(assigned to field filled)
var timeZone = current.u_time_zone_bs; // defined time zone in the incident form which is populating from Business service. Time zone here is Asia/Kolkata
var dur = new GlideDuration();
var schedule = current.u_sla_schedules; // defined Schedule in the incident form which is populating from Business service. Schedule here is 9am-6pm
var sched = new GlideSchedule(schedule , timeZone);
dur =sched.duration(gdt,nowUTC);
current.u_acknowledge_duration=dur;
I tested the above script multiple times, I found that the calculation is being done from 8am-5pm instead of 9am-6pm in Asia/Kolkata time zone. It's calculating one hour early.
NOTE: My system property time zone is Europe/Zurich(UTC+1)
How to make the calculation correctly as per the schedule and the time zone as defined in the business service?
Please help me out. Appreciate your response.
Thanks.