# Perpective Client Timezones not being used when I have it set to do so

**URL:** <https://forum.inductiveautomation.com/t/perpective-client-timezones-not-being-used-when-i-have-it-set-to-do-so/81623>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [November 7, 2023, 8:53pm UTC](https://forum.inductiveautomation.com/t/perpective-client-timezones-not-being-used-when-i-have-it-set-to-do-so/81623 "2023-11-07T20:53:10Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cole\_Townsend](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cole_townsend/32/53149_2.png) [@Cole\_Townsend](https://forum.inductiveautomation.com/u/Cole_Townsend)\
**Post date:** [November 7, 2023, 8:53pm UTC](https://forum.inductiveautomation.com/t/perpective-client-timezones-not-being-used-when-i-have-it-set-to-do-so/81623/1 "2023-11-07T20:53:10Z")

</div>

Hey guys,

I am trying to display a millisecond timestamp in perspective using the browser's local timezone. Despite this, I continue to have the gateway's timezone being used, even though I explicitly defined it to use the client's timezone.

Is there anything I am missing here?  
timezone setting:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/e/ce450635aefcee807aa60a03b75424d7cbe0032d.png)  
property binding:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/e/1ead5fc3df9aa2645f42a0c92fba68eeba60604c.png)  
result in browser:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/a/ea80516b05a945537a119264e2b760dedb36626f.png)

I expect it to show MST instead of CST.  
Any thoughts?

---

<div class="post-metadata">

**Author:** ![Felipe\_CRM](https://avatars.discourse-cdn.com/v4/letter/f/dfb087/32.png) [@Felipe\_CRM](https://forum.inductiveautomation.com/u/Felipe_CRM)\
**Post date:** [November 7, 2023, 9:07pm UTC](https://forum.inductiveautomation.com/t/perpective-client-timezones-not-being-used-when-i-have-it-set-to-do-so/81623/2 "2023-11-07T21:07:19Z")

</div>

The transform runs on the gateway so it cheerfully ignores the project setting. As far as I can tell, the Project time zone property only applies to components where the dates get formatted automatically. A good example is the Date Time Input component. If you were to feed your milliseconds into a binding on the `value` property of one of those, you'd see the formatted date would display with the project time zone.

---

<div class="post-metadata">

**Author:** ![Cole\_Townsend](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cole_townsend/32/53149_2.png) [@Cole\_Townsend](https://forum.inductiveautomation.com/u/Cole_Townsend)\
**Post date:** [November 7, 2023, 9:09pm UTC](https://forum.inductiveautomation.com/t/perpective-client-timezones-not-being-used-when-i-have-it-set-to-do-so/81623/3 "2023-11-07T21:09:01Z")

</div>

Huh, I was always under the assumption that component property bindings ran in the client scope and not the gateway scope.

---

<div class="post-metadata">

**Author:** ![Felipe\_CRM](https://avatars.discourse-cdn.com/v4/letter/f/dfb087/32.png) [@Felipe\_CRM](https://forum.inductiveautomation.com/u/Felipe_CRM)\
**Post date:** [November 7, 2023, 9:11pm UTC](https://forum.inductiveautomation.com/t/perpective-client-timezones-not-being-used-when-i-have-it-set-to-do-so/81623/4 "2023-11-07T21:11:10Z")

</div>

It's Perspective, everything executes on the gateway scope. I really do wish the date functions would automatically take the project timezone into account or have a configurable time zone parameter.

---

<div class="post-metadata">

**Author:** ![Cole\_Townsend](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cole_townsend/32/53149_2.png) [@Cole\_Townsend](https://forum.inductiveautomation.com/u/Cole_Townsend)\
**Post date:** [November 7, 2023, 9:14pm UTC](https://forum.inductiveautomation.com/t/perpective-client-timezones-not-being-used-when-i-have-it-set-to-do-so/81623/5 "2023-11-07T21:14:07Z")

</div>

Well I guess that makes sense. I could probably use the session TimeZoneID somehow to format the datetime into the correct timezone.

---

<div class="post-metadata">

**Author:** ![Cole\_Townsend](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cole_townsend/32/53149_2.png) [@Cole\_Townsend](https://forum.inductiveautomation.com/u/Cole_Townsend)\
**Post date:** [November 7, 2023, 9:27pm UTC](https://forum.inductiveautomation.com/t/perpective-client-timezones-not-being-used-when-i-have-it-set-to-do-so/81623/6 "2023-11-07T21:27:42Z")

</div>

I obviously didn't dig hard enough. This came up once I refined my search slightly:

> [@\[IGN-6614\]What is the best way to format a date (milliseconds) for a specified timezone with Ignition's python scripting](https://forum.inductiveautomation.com/t/ign-6614-what-is-the-best-way-to-format-a-date-milliseconds-for-a-specified-timezone-with-ignitions-python-scripting/64068/7):
>
> Ah, I was overthinking things. SimpleDateFormat extends DateFormat. DateFormat defines setTimeZone(). TimeZone is an instance of java.util.TimeZone, and easiest obtained from an ID. from java.util import TimeZone from java.text import SimpleDateFormat #for tz in TimeZone.getAvailableIDs(): # print tz now = system.date.now() eastern = TimeZone.getTimeZone("America/New\_York") pacific = TimeZone.getTimeZone("America/Los\_Angeles") sdf = SimpleDateFormat("yyyy-MM-dd HH:mm:ss ZZZ") print sdf.ge…

This is my final solution:

```auto
def transform(self, value, quality, timestamp):
	from java.util import TimeZone
	from java.text import SimpleDateFormat	
	tz = TimeZone.getTimeZone(self.session.props.timeZoneId)
	sdf = SimpleDateFormat("E MMM d, h:mm:ss a z")
	sdf.setTimeZone(tz)
	return "Scheduled for: " + sdf.format(system.date.fromMillis(value))

```

---

<div class="post-metadata">

**Author:** ![Tim\_Carlton](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/tim_carlton/32/52835_2.png) [@Tim\_Carlton](https://forum.inductiveautomation.com/u/Tim_Carlton)\
**Post date:** [November 7, 2023, 9:37pm UTC](https://forum.inductiveautomation.com/t/perpective-client-timezones-not-being-used-when-i-have-it-set-to-do-so/81623/7 "2023-11-07T21:37:24Z")

</div>

Changing Project Timezone to _Client_ didn't seem to have any effect on the standard Perspective views when rendered on a browser page for me.

Adding a Property Binding to the Session Props timeZoneId of `this.props.device.timezone.id` did change the presented time to the local timezone as set by the browser (chromium, developer tools, sensors, location -\> override to whatever you want to test and F5 to reload the Perspective page)

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [November 7, 2023, 10:37pm UTC](https://forum.inductiveautomation.com/t/perpective-client-timezones-not-being-used-when-i-have-it-set-to-do-so/81623/8 "2023-11-07T22:37:30Z")

</div>

Once we add a timezone argument to the scripting/expression functions, it should be "easy" for us to pass through a contextual timezone automatically, and for you to override it if you have some other purpose. I'll make a note on the existing internal ticket discussed in that other thread.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [November 7, 2023, 11:59pm UTC](https://forum.inductiveautomation.com/t/perpective-client-timezones-not-being-used-when-i-have-it-set-to-do-so/81623/9 "2023-11-07T23:59:07Z")

</div>

> [@Cole\_Townsend](#):
>
> my final solution

You really should not be doing imports in transforms (or any other `def`s where you can avoid it). Delegate to a project library utility script, like shown here:

> [@Ignition Perspective Page to show the client System date and time](https://forum.inductiveautomation.com/t/ignition-perspective-page-to-show-the-client-system-date-and-time/73265/8):
>
> Sure. I recommend [DateTimeFormatter.ofPattern()](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/time/format/DateTimeFormatter.html#ofPattern(java.lang.String)). But I would move the complexity to a project script module with a DateTimeFormatter instance with your preferred pattern saved as a top level variable. Like so, perhaps: from java.time import ZoneId from java.time.format import DateTimeFormatter defaultFormatter = DateTimeFormatter.ofPattern("YYYY-MM-dd HH:mm") def zonedFormat(ts, zoneid, format=None): formatter = defaultFormatter if format is None else DateTimeFormatter.ofPattern(format) r…

---

<div class="post-metadata">

**Author:** ![Tim\_Carlton](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/tim_carlton/32/52835_2.png) [@Tim\_Carlton](https://forum.inductiveautomation.com/u/Tim_Carlton)\
**Post date:** [November 8, 2023, 2:24pm UTC](https://forum.inductiveautomation.com/t/perpective-client-timezones-not-being-used-when-i-have-it-set-to-do-so/81623/10 "2023-11-08T14:24:32Z")

</div>

I found this article which seems helpful

> **[Time Zones in Perspective](https://support.inductiveautomation.com/hc/en-us/articles/17189847446797-Time-Zones-in-Perspective)**
>
> Introduction
> This document provides guidance on how to support multiple time zones in Ignition 8.1.3 when using Perspective. A Perspective session can run with multiple different time zones simulta...

There might be a clue in there about why changing Project Timezone to client didn't change anything for me. The project Component Session Property was hardcoded (by default?) to America/New York and that value overrides the Project Timezone. Maybe setting the value to "" would enable the Project Timezone setting? (Note that I haven't tested this.)

Unfortunately the article starts out defining the _Perspective Session Timezone_ and discussing how it is set but then transitions to _Browser timezone_ when talking about how things are displayed. Those are not the same thing, and my experiments yesterday indicates that the components don't use _Browser timezone_, at least not the ones that I was looking at.

---

<div class="post-metadata">

**Author:** ![Cole\_Townsend](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cole_townsend/32/53149_2.png) [@Cole\_Townsend](https://forum.inductiveautomation.com/u/Cole_Townsend)\
**Post date:** [November 8, 2023, 3:11pm UTC](https://forum.inductiveautomation.com/t/perpective-client-timezones-not-being-used-when-i-have-it-set-to-do-so/81623/11 "2023-11-08T15:11:04Z")

</div>

Are the module imports not cached or something when the def runs? Do you say this because it's reimporting the module every time the function runs?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [November 8, 2023, 3:13pm UTC](https://forum.inductiveautomation.com/t/perpective-client-timezones-not-being-used-when-i-have-it-set-to-do-so/81623/12 "2023-11-08T15:13:25Z")

</div>

No (the imported module itself is persistently cached, but the import statement won't find it without an expensive lock), and yes.

Same with `def` nested within another `def`, mostly.
