Jump to content

How do I make a visualization dynamically change the datetime value based on the device's time zone setting

Fred Gruhn 2

Recommended Posts

I have a visualization (bar chart) that displays items over time (hours of day). The datetime value is stored as the GMT (UTC) value. Is it possible to convert time displayed to the user's local time (based on their machine's location) So no matter where the user is logged in, they will see the results of the bar chart in their local time.

It's been suggested to use localtime() in ironpython. Has anyone tried this

Link to comment
Share on other sites

You can use IronPython to get the UTC offset. For example:


from datetime import *


now_local = datetime.now()

now_utc = datetime.utcnow()


utc_offset = (now_local - now_utc)

utc_offset = int(float((utc_offset.seconds + utc_offset.days * 24 * 3600)) / 3600)


Document.Properties["timezoneoffset"] = utc_offsetThat stores the UTC offset in a document property called 'timezoneoffset'. Then you can use that to offset your data accordingly with an expression like:



Note: there are simpler ways to get timezones, manipulate them (pytz module)and get total seconds/hours (like with total_seconds() in Python 2.7+), but this does it natively with no extras... And this is more for the Analyst client since on the Web Player ironpython is run on the Web Player server, so you would instead need to get the browser timezone.

Link to comment
Share on other sites

  • 3 years later...



I am working on a use case where we are sharing our visualization dxp using web player Link.


I am facing an issue on timestamp, Data in the visualization have UTC timezone but our clients can be anywhere in the U.S , so is there any way I can convert the timestamp to client local time using any Iron python script.


I am using the above script, it works perfectly fine as far as we open on Analyst but it doesn't work in the web player


Any guidance will be helpful

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...