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 09:15 AM
Actually, I don't want to hardcode timezone. If I run it in Pakistan it should give correct result and if I run it in africa it should also give correct result. how to achieve that?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2024 04:19 PM
Hi @saba tanveer,
Your script is correct, using the getDisplayValue() should always return the time of the current user's timezone.
Timezone set to Pacific/Auckland
Timezone set to US/Hawaii
Not sure how or where you ran the code, but your script works.
Cheers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2024 03:30 AM
Yes it is working but the issue is system timezone selected on instance is africa and I am working in Pakistan. I have a requirement to check if current time has passed or not so it is checking if africa current time has passed or not so, it is creating issue while testing my code because testing team of Pakistan will see current time of Pakistan and Africa team will see current time of africa. I want some dynamic solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2024 02:02 PM
What do you mean it's causing an issue when you are testing it?
Can you elaborate a bit further on what the requirement was and what you have built?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2024 08:24 AM - edited 05-25-2024 08:39 AM
Hi @saba tanveer,
I think I found the solution to your problem. What you need to do is set the time zone for your user record to PST. In order to do so, please follow the steps mentioned in this article - Change the time zone list.
While doing so, you should see something like this -
Once you have moved PST to the list of selected time zones, hit Save.
Now, head to the User icon in the top right corner as shown below and click on Preferences.
Next, click on Display and then you would see the dropdown menu for Time Zone. Select PST. That's it, your profile time zone has now been changed to PST while the system time zone remains as Africa/Johannesburg.
Now, you can run the script and you shall see your local time showing as the result. I tested your script with the IST value as can be seen below.
Hope this helped.