Different time zone issue in scripting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2024 12:42 AM
User timezone on instance is africa/johannesburg and I am working from Pakistan so when I am trying to write script to get current time it is giving me africa/johannesburg time. Is there any way to get the time where system operates automatically without mentioning timezone.
my code:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2024 01:53 AM - edited 05-24-2024 01:54 AM
Hi Saba
Given the joburg time is +2
Try
var gdt = new GlideDateTime();
var gtime1 = new GlideTime();
gtime1.setValue("02:00:00");
gdt.add(gtime1);
gs.print(gdt);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2024 03:45 AM
This code is giving me above result and in my clock time is 15:42
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2024 03:52 AM - edited 05-24-2024 03:58 AM
Hi Saba
That's right.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2024 04:07 AM
Hi @saba tanveer ,
You can use the below code & convert to PST
convertTimetoPST: function(dat){
//convert date to PST timezone
var time = new GlideDateTime(dat);
var targetTimezone = 'PST'; // ensure you give correct timezone Abbreviation
var tz = Packages.java.util.TimeZone.getTimeZone(targetTimezone);
time.setTZ(tz);
var timeZoneOffSet = time.getTZOffset();
time.setNumericValue(time.getNumericValue() + timeZoneOffSet);
return time;
},
If my answer helped you in any way, please mark it as helpful or correct.