# Local time for text input node using datetime picker

**URL:** <https://discourse.nodered.org/t/local-time-for-text-input-node-using-datetime-picker/77559>\
**Category:** General\
**Created:** [14 April 2023 08:10 UTC](https://discourse.nodered.org/t/local-time-for-text-input-node-using-datetime-picker/77559 "2023-04-14T08:10:45Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Switchblade2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/switchblade2/32/60655_2.png) [@Switchblade2](https://discourse.nodered.org/u/Switchblade2)\
**Post date:** [14 April 2023 08:10 UTC](https://discourse.nodered.org/t/local-time-for-text-input-node-using-datetime-picker/77559/1 "2023-04-14T08:10:45Z")

</div>

Hi,

Is there any easy way to get a 'text node' set as 'datetime picker' send the output as local time.  
Currently I get the output in UTC.  
Example:  
When I select 14/4/2023 and 10:00 in the ui the output is  
14/04/2023, 12:00:00 [UTC+2] (= 1681466400000 = 2023-04-14T10:00:00.000Z)

I would like it to return a timestamp corresponding to 14/04/2023, 10:00:00 [UTC+2].

I guess one way is to put a function before & after the text node to adjust the time but I'm wondering there is a smarter way as the adjust functions would need to take into account summer/winter time.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [14 April 2023 08:21 UTC](https://discourse.nodered.org/t/local-time-for-text-input-node-using-datetime-picker/77559/2 "2023-04-14T08:21:56Z")

</div>

The `moment` node?  
`node-red-contrib-moment`

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [14 April 2023 08:40 UTC](https://discourse.nodered.org/t/local-time-for-text-input-node-using-datetime-picker/77559/3 "2023-04-14T08:40:14Z")

</div>

> [@Switchblade2](#):
>
> When I select 14/4/2023 and 10:00 in the ui the output is  
> 14/04/2023, 12:00:00 [UTC+2] (= 1681466400000 = 2023-04-14T10:00:00.000Z)

Do you mean that your local timezone is UTC+2, but when you enter 10:00 it is giving 10:00Z?

Are the machine running node-red and the machine running the browser both set to UTC+2?  
Are you running node-red in Docker or Home Assistant or something other than a native node-red install?  
I think it it possible to override the local timezone in the browser settings, make sure that browser is set to use the system timezone.

---

<div class="post-metadata">

**Author:** ![Switchblade2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/switchblade2/32/60655_2.png) [@Switchblade2](https://discourse.nodered.org/u/Switchblade2)\
**Post date:** [14 April 2023 08:58 UTC](https://discourse.nodered.org/t/local-time-for-text-input-node-using-datetime-picker/77559/4 "2023-04-14T08:58:59Z")

</div>

_Do you mean that your local timezone is UTC+2, but when you enter 10:00 it is giving 10:00Z?_  
Yes

_Are the machine running node-red and the machine running the browser both set to UTC+2?_  
Yes. Tested with Timestamp\>Debug in browser and Date command on Raspberry Pi

I have a native install of Node Red on a Raspberry Pi.  
I'm using Safari browser (no time setting) on a Macbook (time set to local time zone, UTC+2)

---

<div class="post-metadata">

**Author:** ![Switchblade2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/switchblade2/32/60655_2.png) [@Switchblade2](https://discourse.nodered.org/u/Switchblade2)\
**Post date:** [14 April 2023 09:04 UTC](https://discourse.nodered.org/t/local-time-for-text-input-node-using-datetime-picker/77559/5 "2023-04-14T09:04:15Z")

</div>

> [@Trying\_to\_learn](#):
>
> node-red-contrib-moment

Thanks, I'll test it but not sure if it can automatically manage the summer/winter time switch (UTC+2 vs UTC+1)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [14 April 2023 09:04 UTC](https://discourse.nodered.org/t/local-time-for-text-input-node-using-datetime-picker/77559/6 "2023-04-14T09:04:32Z")

</div>

That should not be happening.  
Can you try a different browser?

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [14 April 2023 09:11 UTC](https://discourse.nodered.org/t/local-time-for-text-input-node-using-datetime-picker/77559/7 "2023-04-14T09:11:15Z")

</div>

It should as I use it and it does track _Summertime_ for me.

---

<div class="post-metadata">

**Author:** ![Switchblade2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/switchblade2/32/60655_2.png) [@Switchblade2](https://discourse.nodered.org/u/Switchblade2)\
**Post date:** [14 April 2023 09:12 UTC](https://discourse.nodered.org/t/local-time-for-text-input-node-using-datetime-picker/77559/8 "2023-04-14T09:12:50Z")

</div>

I get the same results over Safari on an iPad.  
Over the weekend I'll test with Chrome and directly on the Raspberry, but need local access for that.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [14 April 2023 09:13 UTC](https://discourse.nodered.org/t/local-time-for-text-input-node-using-datetime-picker/77559/9 "2023-04-14T09:13:57Z")

</div>

> [@Trying\_to\_learn](#):
>
> It should as I use it

The first thing to do here is to find out why the node is returning the wrong time.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [14 April 2023 09:16 UTC](https://discourse.nodered.org/t/local-time-for-text-input-node-using-datetime-picker/77559/10 "2023-04-14T09:16:17Z")

</div>

Can you post a minimal flow showing the error please so I can test exactly what you are doing.  
Are you using the latest version of node-red-dashboard? If not then upgrade that.  
If still doesn't work can you post the full output you get when you stop and start node-red in a shell on the pi using  
`node-red-reload`

---

<div class="post-metadata">

**Author:** ![Switchblade2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/switchblade2/32/60655_2.png) [@Switchblade2](https://discourse.nodered.org/u/Switchblade2)\
**Post date:** [14 April 2023 09:35 UTC](https://discourse.nodered.org/t/local-time-for-text-input-node-using-datetime-picker/77559/11 "2023-04-14T09:35:56Z")

</div>

Here is an example flow.  
If I inject a timestamp it will display as UTC in UI but in the debug it will show as the correct local time  
If I change in the ui then the debug will show the wrong local time.

I'll update node-red-dashboard over the weekend (currently v3.3.1)

```auto
[
    {
        "id": "4d49653279fea87a",
        "type": "tab",
        "label": "test",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "58ca500df7734f6a",
        "type": "ui_text_input",
        "z": "4d49653279fea87a",
        "name": "",
        "label": "test",
        "tooltip": "",
        "group": "a095025ac31861a2",
        "order": 2,
        "width": 4,
        "height": 1,
        "passthru": true,
        "mode": "datetime-local",
        "delay": "500",
        "topic": "topic",
        "sendOnBlur": true,
        "className": "",
        "topicType": "msg",
        "x": 290,
        "y": 80,
        "wires": [
            [
                "ac45236ea4df9b23"
            ]
        ]
    },
    {
        "id": "ac45236ea4df9b23",
        "type": "debug",
        "z": "4d49653279fea87a",
        "name": "debug 7",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 460,
        "y": 80,
        "wires": []
    },
    {
        "id": "10eb98c798096036",
        "type": "inject",
        "z": "4d49653279fea87a",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 140,
        "y": 80,
        "wires": [
            [
                "58ca500df7734f6a"
            ]
        ]
    },
    {
        "id": "a095025ac31861a2",
        "type": "ui_group",
        "name": "Test",
        "tab": "76c928cd.92de08",
        "order": 5,
        "disp": true,
        "width": "6",
        "collapse": false,
        "className": ""
    },
    {
        "id": "76c928cd.92de08",
        "type": "ui_tab",
        "name": "Test",
        "icon": "dashboard",
        "order": 1,
        "disabled": false,
        "hidden": false
    }
]

```

---

<div class="post-metadata">

**Author:** ![cameo69](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cameo69/32/66593_2.png) [@cameo69](https://discourse.nodered.org/u/cameo69)\
**Post date:** [14 April 2023 09:48 UTC](https://discourse.nodered.org/t/local-time-for-text-input-node-using-datetime-picker/77559/12 "2023-04-14T09:48:39Z")

</div>

> [@Switchblade2](#):
>
> timestamp it will display as U

Same here, is this a bug of the UI node? Maybe you can manually changing it via function node.

![output_datepick_01](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/5/55a7f97a387d3d8c0cc6f46ae7b0206b8c578179.gif)

---

<div class="post-metadata">

**Author:** ![Switchblade2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/switchblade2/32/60655_2.png) [@Switchblade2](https://discourse.nodered.org/u/Switchblade2)\
**Post date:** [14 April 2023 09:53 UTC](https://discourse.nodered.org/t/local-time-for-text-input-node-using-datetime-picker/77559/13 "2023-04-14T09:53:49Z")

</div>

Exactly the issue! And nice way to show with a video!

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [15 April 2023 15:06 UTC](https://discourse.nodered.org/t/local-time-for-text-input-node-using-datetime-picker/77559/14 "2023-04-15T15:06:44Z")

</div>

@dceejay are you able to comment on this? It does appear to be sending the incorrect time, and it isn't the 1970 DST issue, or doesn't appear to be anyway.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [15 April 2023 18:21 UTC](https://discourse.nodered.org/t/local-time-for-text-input-node-using-datetime-picker/77559/15 "2023-04-15T18:21:10Z")

</div>

When using the text input in date time mode it relies on whatever rendering the browser and OS decide to give you - you will get different widgets depending on your browser or device. If you click on the returned value in the debug it will show the time in various different formats including UTC, local time, epoch time etc.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [15 April 2023 20:04 UTC](https://discourse.nodered.org/t/local-time-for-text-input-node-using-datetime-picker/77559/16 "2023-04-15T20:04:37Z")

</div>

It isn't that. We are on UTC+1 at the moment, and if I select 15/04/2023 20:40 (which is 19:40 UTC) then in the debug node I see  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/c/7c1c79ead89566affb42505a57666a3667355703.png)

So it is showing 20:40Z, or 21:40 UTC+1, instead of 19:40Z or 20:40 UTC+1

I am seeing that in Chrome and FF.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [15 April 2023 21:43 UTC](https://discourse.nodered.org/t/local-time-for-text-input-node-using-datetime-picker/77559/17 "2023-04-15T21:43:47Z")

</div>

Yes. The date time-local input option doesn’t seem to handle things like that.

> **[\- HTML: HyperText Markup Language | MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/datetime-local)**
>
> elements of type datetime-local create input controls that let the user easily enter both a date and a time, including the year, month, and day as well as the time in hours and minutes.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [16 April 2023 09:16 UTC](https://discourse.nodered.org/t/local-time-for-text-input-node-using-datetime-picker/77559/18 "2023-04-16T09:16:56Z")

</div>

That doesn't seem to cover it, as far as I can see. This flow has a datetime picker using the node, and also a native html version using datetime\_local in a ui\_template.  
The node returns an epoch timestamp, which I convert to an ISO string for display in a debug node and the ui\_template returns it as a string. The ui\_template gets it right, but the node is an hour out.

```auto
[{"id":"58ca500df7734f6a","type":"ui_text_input","z":"4d49653279fea87a","name":"","label":"text input node","tooltip":"","group":"a095025ac31861a2","order":2,"width":4,"height":1,"passthru":true,"mode":"datetime-local","delay":"500","topic":"topic","sendOnBlur":true,"className":"","topicType":"msg","x":160,"y":80,"wires":[["64f9d1a5d809e2f7"]]},{"id":"ac45236ea4df9b23","type":"debug","z":"4d49653279fea87a","name":"Text input node","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":540,"y":80,"wires":[]},{"id":"2f8334f4.cefd7c","type":"ui_template","z":"4d49653279fea87a","group":"a095025ac31861a2","name":"datetime_local in ui_template","order":5,"width":0,"height":0,"format":"<input ng-model=\"me.item.value\" type=\"datetime-local\"\n ng-change=\"send({payload: me.item.value})\">","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":true,"templateScope":"local","className":"","x":200,"y":140,"wires":[["703b20675f7f4e7b"]]},{"id":"703b20675f7f4e7b","type":"debug","z":"4d49653279fea87a","name":"ui_template","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":530,"y":140,"wires":[]},{"id":"64f9d1a5d809e2f7","type":"function","z":"4d49653279fea87a","name":"toISOString()","func":"msg.payload = new Date(msg.payload).toISOString()\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":350,"y":80,"wires":[["ac45236ea4df9b23"]]},{"id":"a095025ac31861a2","type":"ui_group","name":"Test","tab":"76c928cd.92de08","order":5,"disp":true,"width":"6","collapse":false,"className":""},{"id":"76c928cd.92de08","type":"ui_tab","name":"Test","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

```

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [16 April 2023 10:53 UTC](https://discourse.nodered.org/t/local-time-for-text-input-node-using-datetime-picker/77559/19 "2023-04-16T10:53:31Z")

</div>

OK - have pushed a possible fix to master branch. (not on npm)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [16 April 2023 11:26 UTC](https://discourse.nodered.org/t/local-time-for-text-input-node-using-datetime-picker/77559/20 "2023-04-16T11:26:07Z")

</div>

Does that count as a breaking change? It appears to have been like that for a long time.

[Next page](https://discourse.nodered.org/t/local-time-for-text-input-node-using-datetime-picker/77559.md?page=2)
