# Timezones...server & browser

**URL:** <https://discourse.nodered.org/t/timezones-server-browser/66988>\
**Category:** General\
**Created:** [26 August 2022 23:15 UTC](https://discourse.nodered.org/t/timezones-server-browser/66988 "2022-08-26T23:15:20Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jimwhitfield](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jimwhitfield/32/20084_2.png) [@jimwhitfield](https://discourse.nodered.org/u/jimwhitfield)\
**Post date:** [26 August 2022 23:15 UTC](https://discourse.nodered.org/t/timezones-server-browser/66988/1 "2022-08-26T23:15:20Z")

</div>

Hello, I am reasonably proficient with Node Red, but at the moment, I don't have a solution to my problem.  
I use Dashboard to display a graph of data over time. It works great. If I'm on the West Coast, the "last three hours" uses the correct times as x axis. I changed Windows to say I'm on the East Coast, and the x axis times update perfectly without a page refresh. Fabulous!

On the same page, I pull longer-term data from InfluxDB. I run the results thru a function node (called "prettify graph") where I massage the database's results into human friendly results. Part of that is, naturally, rendering the (user's) time.  
Sharing my code will help the context of my question:

```auto
now = new Date();
const user_timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
now.toLocaleString('en-US', { timeZone: user_timezone })
node.log("user_timezone is "+user_timezone);
node.log("TZ offset is "+now.getTimezoneOffset(user_timezone) );
for (var x in rtn.labels) {
    var this_time = Date.parse(rtn.labels[x]);
    rtn.labels[x] = new Intl.DateTimeFormat('en-US', { date:false, hour:'numeric',minute:'numeric', hour12: true, timeZone:user_timezone }).format(this_time);
}

```

So, `const user_timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;`  
is great for finding what the Browser sees is the timezone. BUT, I'm running node red on a linux host unchanged as UTC, and I'm doing the sensible thing of keeping it that way, because I may have viewers from any timezone. When I look at the node log on the server, alas and of course, I see  
[function:Prettify graph] user\_timezone is UTC  
[function:Prettify graph] TZ offset is 0

The question: How do I get the browser's results of `const user_timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;` into the context of the server's node/javascript/vm execution environment? I bet it's "simple", but I can't think of it nor find it. (I cited that Dashboard's Line Chart node behaves correctly, but I think that's a because it does the rendering on the browser, not the server.)

Thanks in advance for pondering my question!

---

<div class="post-metadata">

**Author:** ![paulkeates](https://avatars.discourse-cdn.com/v4/letter/p/9de053/32.png) [@paulkeates](https://discourse.nodered.org/u/paulkeates)\
**Post date:** [26 August 2022 23:27 UTC](https://discourse.nodered.org/t/timezones-server-browser/66988/2 "2022-08-26T23:27:12Z")

</div>

Hi,

I honestly can't say I've had EXEACTLY your issue, but I have had to do some time-zone 'manipulation' to solve display issues.

The easiest way for me was to install the 'moment' node (node-red-contrib-moment) and explore it. Forcing all TZ to UTC was helpful - DB, UI etc.

I hope this helps - perhaps in a small way.

Cheers,

Paul

---

<div class="post-metadata">

**Author:** ![jimwhitfield](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jimwhitfield/32/20084_2.png) [@jimwhitfield](https://discourse.nodered.org/u/jimwhitfield)\
**Post date:** [27 August 2022 00:54 UTC](https://discourse.nodered.org/t/timezones-server-browser/66988/3 "2022-08-27T00:54:30Z")

</div>

Thanks @paulkeates I've used moment and it can be very helpful. Alas, I fear moment wouldn't have the (client-located) information that's needed, either.  
What I need (I think) is for the server to know a bit of information (the timezone) from the browser, but without the user having to do anything to send that information up. HTTP headers came to mind, but I see they do not contain the browser's timezone.  
I just want a single simple line of javascript to run in the browser and to report the value up to node. (sort of the approach mentioned here, in SO's 13th question: [html - Determine a user's timezone - Stack Overflow](https://stackoverflow.com/a/29))

Thinking aloud...  
I've used the OnConnect node to kick off nodes that can even force information down to the browser. Separately, I could probably have a bit of node.js code that runs a bit of client initialization when that hits the browser. Then the trick would be to actively fetch or await a push of that (timezone) information.

Pondering continues...

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [27 August 2022 01:20 UTC](https://discourse.nodered.org/t/timezones-server-browser/66988/4 "2022-08-27T01:20:06Z")

</div>

You can use the ui-template to return browser Date() properties  
Take a look [here](https://discourse.nodered.org/t/timezone-offset-of-the-dashboard-user/63929/2)

---

<div class="post-metadata">

**Author:** ![jimwhitfield](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jimwhitfield/32/20084_2.png) [@jimwhitfield](https://discourse.nodered.org/u/jimwhitfield)\
**Post date:** [27 August 2022 05:56 UTC](https://discourse.nodered.org/t/timezones-server-browser/66988/5 "2022-08-27T05:56:12Z")

</div>

Awesome, Thanks! I'll mark this as the solution once I get to try it out.

---

<div class="post-metadata">

**Author:** ![jimwhitfield](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jimwhitfield/32/20084_2.png) [@jimwhitfield](https://discourse.nodered.org/u/jimwhitfield)\
**Post date:** [31 August 2022 01:12 UTC](https://discourse.nodered.org/t/timezones-server-browser/66988/6 "2022-08-31T01:12:11Z")

</div>

Oh phew, ui-template not ui-builder. I want to get familiar with ui-builder but not to solve this.  
I see the nice little importable snippet over on the other page, and was able to import and try it out and found that it'll solve my problem. Thanks

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [14 September 2022 01:12 UTC](https://discourse.nodered.org/t/timezones-server-browser/66988/7 "2022-09-14T01:12:26Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
