# Using msg.ui\_control to apply timezone offset to datetime object in ui-table

**URL:** https://discourse.nodered.org/t/using-msg-ui-control-to-apply-timezone-offset-to-datetime-object-in-ui-table/75919
**Category:** Dashboard
**Tags:** node-red-dashboard
**Created:** [1 March 2023 09:35 UTC](https://discourse.nodered.org/t/using-msg-ui-control-to-apply-timezone-offset-to-datetime-object-in-ui-table/75919 "2023-03-01T09:35:51Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![scrambled](https://avatars.discourse-cdn.com/v4/letter/s/9fc29f/32.png) [@scrambled](https://discourse.nodered.org/u/scrambled)
#### Post date: [1 March 2023 09:35 UTC](https://discourse.nodered.org/t/using-msg-ui-control-to-apply-timezone-offset-to-datetime-object-in-ui-table/75919/1 "2023-03-01T09:35:51Z")

</div>

Hello,

I am a Node-RED and JS newbie that would greatly appreciate some assistance on a dashboard issue I am trying to solve.

I have some timestamps stored as UTC datetime objects that I would like to show in a ui-table column. [This thread](https://discourse.nodered.org/t/solved-how-to-change-timestamps-in-objects-to-date-time-for-ui-table/28289) helped me apply my desired formatting to show in the table, but I cannot seem to get timezone offsetting to work. I can apply timezone offset using JSONata expressions, but not sure if there is a way to embed that into the msg.ui\_control JSON. I have tried adding a "timezone" parameter to no avail:

```auto
{
    "tabulator": {
        "columns": [
            {
                "formatter": "datetime",
                "formatterParams": {
                    "inputFormat": "x",
                    "outputFormat": "DD. MMMM YYYY hh:mm:ss",
                    "invalidPlaceholder": "(invalid date)",
					"timezone": "Australia/Brisbane"
                },
                "title": "Last Seen",
                "field": "last_seen"
            }
        ]
    }
}

```

The tabulator [documentation](https://tabulator.info/docs/5.4/format#formatter-datetime) says the luxon.js library is required for date/time formatting but it seems the output formatting works with the built-in moment.js features. I am hoping there is a way to do the same for timezone offsets?

Thanks

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [1 March 2023 10:06 UTC](https://discourse.nodered.org/t/using-msg-ui-control-to-apply-timezone-offset-to-datetime-object-in-ui-table/75919/2 "2023-03-01T10:06:45Z")

</div>

As I understand it, moment will convert UTC timestamps to the local of the browser running it. The idea is that a timestamp right now would display in my timezone (America/New\_York) but on your device it would use your timezone "Australia/Brisbane".

Remember, formatting the output is different than converting it to a different time zone. If you want it to display in a different timezone then yes, you will have to do what the tabulator documentation requires.

---

<div class="post-metadata">

### Author: ![scrambled](https://avatars.discourse-cdn.com/v4/letter/s/9fc29f/32.png) [@scrambled](https://discourse.nodered.org/u/scrambled)
#### Post date: [1 March 2023 11:38 UTC](https://discourse.nodered.org/t/using-msg-ui-control-to-apply-timezone-offset-to-datetime-object-in-ui-table/75919/3 "2023-03-01T11:38:46Z")

</div>

Thanks, I see...

> [@zenofmud](#):
>
> Remember, formatting the output is different than converting it to a different time zone. If you want it to display in a different timezone then yes, you will have to do what the tabulator documentation requires.

Would this be a matter of installing luxon.js and importing it via `functionGlobalContext` in settings.js? I note that usually you would need to then do a `global.get()` in a function node, but since the dependency is in the ui-table node, how would that work?

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [1 March 2023 11:42 UTC](https://discourse.nodered.org/t/using-msg-ui-control-to-apply-timezone-offset-to-datetime-object-in-ui-table/75919/4 "2023-03-01T11:42:32Z")

</div>

> [@scrambled](#):
>
> Would this be a matter of installing luxon.js and importing it via `functionGlobalContext` in settings.js?

I don't know since I've never done it. Give it a try and see what happens

---

<div class="post-metadata">

### Author: ![scrambled](https://avatars.discourse-cdn.com/v4/letter/s/9fc29f/32.png) [@scrambled](https://discourse.nodered.org/u/scrambled)
#### Post date: [2 March 2023 01:13 UTC](https://discourse.nodered.org/t/using-msg-ui-control-to-apply-timezone-offset-to-datetime-object-in-ui-table/75919/5 "2023-03-02T01:13:00Z")

</div>

Okay, I gave it a go. I was able call luxon functions in a function node by invoking the global context variable but unfortunately I cannot get ui-table itself to pick it up for applying timezone offsets. I tried using the `formatterParams` timezone parameter specified in the tabulator documentation and also tried calling luxon in a custom formatter function using `global.get()`. Neither seem to work and doing the latter actually breaks the entire ui\_control message.

The (kind of annoying) workaround I have at the moment is to store my datetime in local time and convert it back to UTC when I need to pass it to somewhere else that is expecting UTC.

---

<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: [1 April 2023 01:13 UTC](https://discourse.nodered.org/t/using-msg-ui-control-to-apply-timezone-offset-to-datetime-object-in-ui-table/75919/6 "2023-04-01T01:13:42Z")

</div>

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