# Timestamp to current date and time?

**URL:** <https://discourse.nodered.org/t/timestamp-to-current-date-and-time/873>\
**Category:** General\
**Created:** [17 June 2018 15:28 UTC](https://discourse.nodered.org/t/timestamp-to-current-date-and-time/873 "2018-06-17T15:28:51Z")\
**Posts on this page:** 11\
**Page:** 2

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [26 July 2019 09:42 UTC](https://discourse.nodered.org/t/timestamp-to-current-date-and-time/873/22 "2019-07-26T09:42:16Z")

</div>

> [@igrowing](#):
>
> Seems I took this warning too seriously.

Moment is very good at what it does, but as Julian has pointed out - it's a true heavyweight!

`node-red-contrib-moment` code size = **7MB**  
`node-red-contrib-simpletime` code size = 40KB  
`node-red-dashboard` code size = 3.7MB  
`node-red-contrib-ramp-thermostat` code size = 72KB

---

<div class="post-metadata">

**Author:** ![igrowing](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/igrowing/32/663_2.png) [@igrowing](https://discourse.nodered.org/u/igrowing)\
**Post date:** [26 July 2019 11:33 UTC](https://discourse.nodered.org/t/timestamp-to-current-date-and-time/873/23 "2019-07-26T11:33:06Z")

</div>

Thank you, Nick.  
I ended up with simple function:

```auto
var now = new Date().toLocaleString("en-GB");
return {payload: now};

```

---

<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:** [26 July 2019 18:55 UTC](https://discourse.nodered.org/t/timestamp-to-current-date-and-time/873/24 "2019-07-26T18:55:39Z")

</div>

> [@Paul-Reed](#):
>
> Moment is very good at what it does, but as Julian has pointed out - it's a true heavyweight!
> 
> `node-red-contrib-moment` code size = **7MB**

I've never been known as a lightweight that's for sure! 😄

---

<div class="post-metadata">

**Author:** ![ajaybnl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ajaybnl/32/97442_2.png) [@ajaybnl](https://discourse.nodered.org/u/ajaybnl)\
**Post date:** [14 August 2019 06:21 UTC](https://discourse.nodered.org/t/timestamp-to-current-date-and-time/873/25 "2019-08-14T06:21:45Z")

</div>

**Thank you!**

---

<div class="post-metadata">

**Author:** ![vlturner](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/vlturner/32/15211_2.png) [@vlturner](https://discourse.nodered.org/u/vlturner)\
**Post date:** [31 January 2020 00:30 UTC](https://discourse.nodered.org/t/timestamp-to-current-date-and-time/873/26 "2020-01-31T00:30:09Z")

</div>

So I read this and couldn't seem to get it to populate this correctly.

`msg.payload = {state:true,timestamp:1579362774639}`

So the inbound message is a boolean 0 or 1 value without the "state:" for a ui\_statetrail node.

I keep losing either the boolean or the timestamp.

Any suggestion here?

---

<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:** [31 January 2020 01:01 UTC](https://discourse.nodered.org/t/timestamp-to-current-date-and-time/873/27 "2020-01-31T01:01:30Z")

</div>

> [@vlturner](#):
>
> msg.payload = {state:true,timestamp:1579362774639}

try msg.payload = {`"`state`"`:true,`"`timestamp`"`:1579362774639}

---

<div class="post-metadata">

**Author:** ![vlturner](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/vlturner/32/15211_2.png) [@vlturner](https://discourse.nodered.org/u/vlturner)\
**Post date:** [31 January 2020 02:54 UTC](https://discourse.nodered.org/t/timestamp-to-current-date-and-time/873/28 "2020-01-31T02:54:32Z")

</div>

Tried that I need the timestamp to be now() and the state as the inbound boolean value

---

<div class="post-metadata">

**Author:** ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)\
**Post date:** [31 January 2020 08:54 UTC](https://discourse.nodered.org/t/timestamp-to-current-date-and-time/873/29 "2020-01-31T08:54:20Z")

</div>

How about

> msg.payload = {"state":msg.payload,"timestamp":Date.now()}

?

---

<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:** [31 January 2020 10:29 UTC](https://discourse.nodered.org/t/timestamp-to-current-date-and-time/873/30 "2020-01-31T10:29:42Z")

</div>

Or, as I mentioned, if you need the timestamp in seconds rather than ms:

```auto
msg.payload = { 
    "state": msg.payload, 
    "timestamp": ( Date.now() / 1000 ) 
}

```

---

<div class="post-metadata">

**Author:** ![syoma755](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/syoma755/32/14687_2.png) [@syoma755](https://discourse.nodered.org/u/syoma755)\
**Post date:** [6 July 2020 19:11 UTC](https://discourse.nodered.org/t/timestamp-to-current-date-and-time/873/31 "2020-07-06T19:11:42Z")

</div>

> [@igrowing](#):
>
> How to format $now() to human readable and local timezone format?

Use $now('[D01].[M01].[Y0001] [H01]:[m01]:[s01]', '+0200'). Where +0200 is an offset of your time zone. This will result in something like this:  
"06.07.2020 21:07:53"

Taken from here: [Date/Time functions · JSONata](https://docs.jsonata.org/date-time-functions)

---

<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:** [6 July 2020 20:33 UTC](https://discourse.nodered.org/t/timestamp-to-current-date-and-time/873/32 "2020-07-06T20:33:38Z")

</div>

Closed on 6 July 2020 20:33 UTC



[Previous page](https://discourse.nodered.org/t/timestamp-to-current-date-and-time/873.md?page=1)
