# Timestamp conversion to date totally off

**URL:** <https://discourse.nodered.org/t/timestamp-conversion-to-date-totally-off/41872>\
**Category:** General\
**Created:** [2 March 2021 05:23 UTC](https://discourse.nodered.org/t/timestamp-conversion-to-date-totally-off/41872 "2021-03-02T05:23:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bstabens](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bstabens/32/34238_2.png) [@bstabens](https://discourse.nodered.org/u/bstabens)\
**Post date:** [2 March 2021 05:23 UTC](https://discourse.nodered.org/t/timestamp-conversion-to-date-totally-off/41872/1 "2021-03-02T05:23:18Z")

</div>

I have an inject node I run periodically. I take msg.timestamp and try to convert it to human readable form

```auto
var a = new Date();
msg.payload = { "Time": a.toLocaleTimeString(msg.timestamp*1000)};
return msg

```

And I get all kinds of times, sometimes even the right one, seemingly without a pattern. The node injects every ten minutes, and the times I get are not even progressing all the time, but seem totally random.  
Yes, the Raspberry the server is running on has the correct timezone, and the msg.timestamp of the processing function node has the correct timestamp all the time.

I just don't get it. Where can a simple inject - process go so wrong???

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [2 March 2021 06:01 UTC](https://discourse.nodered.org/t/timestamp-conversion-to-date-totally-off/41872/2 "2021-03-02T06:01:42Z")

</div>

Try...

```auto
var a = new Date(msg.timestamp);
msg.payload = { "Time": a.toLocaleTimeString('en-US')}; 
return msg

```

Basically, always check [mdn](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleTimeString)

---

<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 May 2021 06:02 UTC](https://discourse.nodered.org/t/timestamp-conversion-to-date-totally-off/41872/3 "2021-05-01T06:02:23Z")

</div>

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