# Feedback: Adding format options to 'timestamp' Inject option

**URL:** <https://discourse.nodered.org/t/feedback-adding-format-options-to-timestamp-inject-option/83419>\
**Category:** Core Development\
**Created:** [4 December 2023 17:08 UTC](https://discourse.nodered.org/t/feedback-adding-format-options-to-timestamp-inject-option/83419 "2023-12-04T17:08:29Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [4 December 2023 17:08 UTC](https://discourse.nodered.org/t/feedback-adding-format-options-to-timestamp-inject-option/83419/1 "2023-12-04T17:08:29Z")

</div>

Hi,

I've raised a PR that adds the ability to select a format for the timestamp option in the Inject node (and Change node... and any other node using the built-in TypedInput).

Currently, the timestamp option generates a value that is milliseconds since epoch. A common scenario we see is Function nodes then being used to reformat that into some other common representation.

To keep things simple, I'm proposing to offer a _short_ list of commonly useful formats. I'm inviting feedback from the community on what options should be on the list.

Before anyone suggests it, it is feasible to add a 'custom' option that lets the user enter the format string manually... but before going that route, I'd like to make sure we have a good set of built-in choices.

Comments here or on the PR (linked below)...

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/4/74327da9c6dc7e373b74fc08835d4649c4148ea0.png)

> <https://github.com/node-red/node-red/pull/4468>
>
> This allows the \`timestamp\` TypedInput to also specify a format for the value.
> …
> Currently, it always results in milliseconds since epoch, however a common use case it to then reformat it as a string for some other purpose. It would be better if that formatting could be done directly.
> 
> As it stands, this adds a very small set of formats as shown here:
> 
> \<img width="305" alt="image" src="https://github.com/node-red/node-red/assets/51083/317c5bc1-d8c6-4ffa-a47f-4acc032748fd"\>
> 
> Under the covers it uses \`moment\` as we already have that as a dependency - so in theory could use any moment-valid format string. However, don't want to make it too complex - so would prefer to offer a short list of 'common' formats that are useful.
> 
> At a stretch it \*could\* add a 'custom' option to allow the full format string to be set - but that's out of scope of this quick iteration.
> 
> As this is a built-in type of the TypedInput, this will be useful for \*any\* node that uses the \`date\` type already. This is as long as they use the \`RED.util.evaluateNodeProperty\` helper function as that will do the work.
> 
> For the core nodes, this will apply to the Inject node and Change node.

---

<div class="post-metadata">

**Author:** ![GogoVega](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gogovega/32/71313_2.png) [@GogoVega](https://discourse.nodered.org/u/GogoVega)\
**Post date:** [4 December 2023 17:12 UTC](https://discourse.nodered.org/t/feedback-adding-format-options-to-timestamp-inject-option/83419/2 "2023-12-04T17:12:06Z")

</div>

What about `toLocaleString` ?

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [4 December 2023 17:13 UTC](https://discourse.nodered.org/t/feedback-adding-format-options-to-timestamp-inject-option/83419/3 "2023-12-04T17:13:37Z")

</div>

Localisation is a bit of a tricky subject as it requires the node.js runtime locale to be set properly for the end user. That isn't always going to be the case - a cloud hosted instance for example will typically have a locale different to the end user.

It is the type of can-of-worms I'm hoping to avoid for this quick feature 🙂

---

<div class="post-metadata">

**Author:** ![GogoVega](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gogovega/32/71313_2.png) [@GogoVega](https://discourse.nodered.org/u/GogoVega)\
**Post date:** [4 December 2023 17:16 UTC](https://discourse.nodered.org/t/feedback-adding-format-options-to-timestamp-inject-option/83419/4 "2023-12-04T17:16:16Z")

</div>

We can consider a list of options for `toLocaleString` like "en-gb", "fr-fr"...

The function accept local string so no env needed

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [4 December 2023 17:18 UTC](https://discourse.nodered.org/t/feedback-adding-format-options-to-timestamp-inject-option/83419/5 "2023-12-04T17:18:22Z")

</div>

Adding an output of a native `Date` object can be useful.  
usually this is done in a function node `new Date(msg.payload)`

A small thing of course - but can reduce the need downstream

**EDIT**  
I can see @Steve-Mcl has already requested this on the PR 😄

---

<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:** [4 December 2023 17:23 UTC](https://discourse.nodered.org/t/feedback-adding-format-options-to-timestamp-inject-option/83419/6 "2023-12-04T17:23:08Z")

</div>

For the last three options are those UTC or local timezone?

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [4 December 2023 17:44 UTC](https://discourse.nodered.org/t/feedback-adding-format-options-to-timestamp-inject-option/83419/7 "2023-12-04T17:44:36Z")

</div>

What do you want it to be? I'm looking for feedback and ideas at this stage.

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [4 December 2023 18:24 UTC](https://discourse.nodered.org/t/feedback-adding-format-options-to-timestamp-inject-option/83419/8 "2023-12-04T18:24:20Z")

</div>

> [@knolleary](#):
>
> What do you want it to be? I'm looking for feedback and ideas at this stage.

Congratulations on the can of worms Nick 😉

![Screenshot 2023-12-04 at 18.23.36](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/2/128ba1365228c28568f0d79a36f257d8c4588a4a.png)

Its a bit meh!!  
but if something like this is considered - maybe a check box underneath ("Use Local timezone") instead of a duplicated list, and default to UTC if not detected.

---

<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:** [4 December 2023 21:12 UTC](https://discourse.nodered.org/t/feedback-adding-format-options-to-timestamp-inject-option/83419/9 "2023-12-04T21:12:29Z")

</div>

> [@marcus-j-davies](#):
>
> default to UTC if not detected.

I think the default should be local, in fact I am not sure that the UTC versions are particularly useful. Even the ISO format will generally show local time with timezone.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [4 December 2023 21:23 UTC](https://discourse.nodered.org/t/feedback-adding-format-options-to-timestamp-inject-option/83419/10 "2023-12-04T21:23:53Z")

</div>

> [@knolleary](#):
>
> What do you want it to be? I'm looking for feedback and ideas at this stage.

UTC - we should encourage UTC use mostly since it avoids processing issues. If people have easy options to use local, they are likely to use it and get caught out in the usual date/time processing gotya's.

> [@marcus-j-davies](#):
>
> Its a bit meh!!  
> but if something like this is considered

Please lets keep it simple, this really could easily get out of hand. JavaScript date/time and ISO8601 are obvious and useful choices. Beyond that, you are really getting into design rather than processing choices.

And yes, I'm aware of the irony of me of all people asking for simplicity! 😎

---

<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:** [4 December 2023 21:34 UTC](https://discourse.nodered.org/t/feedback-adding-format-options-to-timestamp-inject-option/83419/11 "2023-12-04T21:34:06Z")

</div>

> [@TotallyInformation](#):
>
> UTC - we should encourage UTC use mostly since it avoids processing issues. If people have easy options to use local, they are likely to use it and get caught out in the usual date/time processing gotya's.

In that case I don't think we should provide the options that do not include the timezone. It will just cause confusion and additional traffic here.

---

<div class="post-metadata">

**Author:** ![chrisn-au](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/chrisn-au/32/25504_2.png) [@chrisn-au](https://discourse.nodered.org/u/chrisn-au)\
**Post date:** [4 December 2023 22:24 UTC](https://discourse.nodered.org/t/feedback-adding-format-options-to-timestamp-inject-option/83419/12 "2023-12-04T22:24:43Z")

</div>

My preference would be local timezone - For me, If I would be using this capability it would be for easy viewing of dates, It would reduce the cognitive load to have it in local time. If I want to do UTC things then i take the time stamp and process it.

Good idea btw

---

<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:** [5 December 2023 09:36 UTC](https://discourse.nodered.org/t/feedback-adding-format-options-to-timestamp-inject-option/83419/13 "2023-12-05T09:36:49Z")

</div>

> [@TotallyInformation](#):
>
> we should encourage UTC

I have difficulty seeing a use case for HH:mm:ss in UTC. Or YYYY-MM-DD.

---

<div class="post-metadata">

**Author:** ![magnus-h](https://avatars.discourse-cdn.com/v4/letter/m/b5ac83/32.png) [@magnus-h](https://discourse.nodered.org/u/magnus-h)\
**Post date:** [5 December 2023 11:15 UTC](https://discourse.nodered.org/t/feedback-adding-format-options-to-timestamp-inject-option/83419/14 "2023-12-05T11:15:57Z")

</div>

We are operating in different time zones so plain local without time zone context has no meaning to us, therefore ISO8601. And if that is in Zulu or Local or whichever timezone doesn't matter, as long as we have that timezone information. (But I'd prefer Zulu time...)

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [5 December 2023 14:01 UTC](https://discourse.nodered.org/t/feedback-adding-format-options-to-timestamp-inject-option/83419/15 "2023-12-05T14:01:48Z")

</div>

ISO8601 is always in UTC.

---

<div class="post-metadata">

**Author:** ![magnus-h](https://avatars.discourse-cdn.com/v4/letter/m/b5ac83/32.png) [@magnus-h](https://discourse.nodered.org/u/magnus-h)\
**Post date:** [5 December 2023 14:32 UTC](https://discourse.nodered.org/t/feedback-adding-format-options-to-timestamp-inject-option/83419/16 "2023-12-05T14:32:04Z")

</div>

In ISO8601 you have the time zone designator. It can be "Z" for Zulu time (aka UTC) or an offset from UTC. If you omit this zone designator, you should assume that the time is in local time. But then you have no information of _what_ local time, i.e., _what_ the offset from UTC is for that time.  
So by omitting time zone designator you get the local time, but without info on _what_ local 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:** [5 December 2023 14:36 UTC](https://discourse.nodered.org/t/feedback-adding-format-options-to-timestamp-inject-option/83419/17 "2023-12-05T14:36:00Z")

</div>

> [@TotallyInformation](#):
>
> ISO8601 is always in UTC.

It can be something like  
2023-12-05T20:20:39+07:00  
which is effectively local time and offset.

---

<div class="post-metadata">

**Author:** ![SeRiusRod](https://avatars.discourse-cdn.com/v4/letter/s/278dde/32.png) [@SeRiusRod](https://discourse.nodered.org/u/SeRiusRod)\
**Post date:** [5 December 2023 14:42 UTC](https://discourse.nodered.org/t/feedback-adding-format-options-to-timestamp-inject-option/83419/18 "2023-12-05T14:42:02Z")

</div>

Writing to database would always be in UTC to avoid problems with clients in different TZ.  
I'm sure that's what @TotallyInformation was thinking when writing his previous message.

But most of the users want to open blinds at some local hour.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [5 December 2023 14:50 UTC](https://discourse.nodered.org/t/feedback-adding-format-options-to-timestamp-inject-option/83419/19 "2023-12-05T14:50:03Z")

</div>

> [@magnus-h](#):
>
> In ISO8601 you have the time zone designator. It can be "Z" for Zulu time (aka UTC) or an offset from UTC. If you omit this zone designator, you should assume that the time is in local time.

So used to using it that I forgot you can change the TZ. 🙂 Because most people sensibly use it in UTC. 😀

---

<div class="post-metadata">

**Author:** ![gemini86](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gemini86/32/70967_2.png) [@gemini86](https://discourse.nodered.org/u/gemini86)\
**Post date:** [6 December 2023 18:22 UTC](https://discourse.nodered.org/t/feedback-adding-format-options-to-timestamp-inject-option/83419/20 "2023-12-06T18:22:48Z")

</div>

This is great! After thinking about it a bit, I think that using UTC for these formatting options will only lead to more function nodes, so locale should be used. If the system locale is not set correctly and cannot be changed, or if this is for an app that would have users from different locales, that should be handled the current way through dashboard templates etc.

[Next page](https://discourse.nodered.org/t/feedback-adding-format-options-to-timestamp-inject-option/83419.md?page=2)
