How do you convert a time to the correct timezone?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2023 10:06 AM
I have a UI page that has a date/time field that returns the value in format: 2023-07-07 11:13
What I need to do is take a look at the time entered and assume it's sent in a specific time zone, and then check if the selected time is inSchedule.
This is being called by a script include so we are passing in the time in format shown above AND a timezone such as US/Central or US/Eastern.
What I am trying to do is take the time that was input on the form and set that as the time for the selected timezone rather than the user's timezone and it doesn't look like that's happening in my code below. It looks like it's converting my 11:13 time (in Central) to 06:13 instead and I'm not able to calculate which schedule the time is within.
Am I missing a step?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2023 12:32 PM
HI @e_wilber
In your code, it seems that you are correctly setting the timezone for the GlideDateTime object. But, the issue lies in the way you're using the getDisplayValue() method. The getDisplayValue() method returns the date and time value in the user's timezone, not the specified timezone.
you should use the getNumericValue() method instead. hope this helps.
Also see these links Convert date to another time zone
Converting specified Time Date