# Convert Date Time to Unix time

**URL:** <https://discourse.nodered.org/t/convert-date-time-to-unix-time/19787>\
**Category:** General\
**Created:** [31 December 2019 21:40 UTC](https://discourse.nodered.org/t/convert-date-time-to-unix-time/19787 "2019-12-31T21:40:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mitchdennis](https://avatars.discourse-cdn.com/v4/letter/m/f14d63/32.png) [@mitchdennis](https://discourse.nodered.org/u/mitchdennis)\
**Post date:** [31 December 2019 21:40 UTC](https://discourse.nodered.org/t/convert-date-time-to-unix-time/19787/1 "2019-12-31T21:40:36Z")

</div>

Hi all

I have a message output being read from a CSV file that is in this format "GPS Time: "Sun Dec 01 08:50:14 PST 2019".Does anybody know how to convert it to a Unix time.  
Thanks  
Dennis Mitchell

---

<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:** [31 December 2019 22:10 UTC](https://discourse.nodered.org/t/convert-date-time-to-unix-time/19787/2 "2019-12-31T22:10:04Z")

</div>

In your other post you showed it already converted  
GPS Time: 1577775035485  
Since you already have an active thread discussing how to format the data for influx it would really be better to keep it all in one thread.

---

<div class="post-metadata">

**Author:** ![mitchdennis](https://avatars.discourse-cdn.com/v4/letter/m/f14d63/32.png) [@mitchdennis](https://discourse.nodered.org/u/mitchdennis)\
**Post date:** [31 December 2019 22:32 UTC](https://discourse.nodered.org/t/convert-date-time-to-unix-time/19787/3 "2019-12-31T22:32:45Z")

</div>

Hi Colin

I thought I had it converted using the change node using the time stamp output but this is the current time not the time from my data.

---

<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:** [31 December 2019 22:43 UTC](https://discourse.nodered.org/t/convert-date-time-to-unix-time/19787/4 "2019-12-31T22:43:16Z")

</div>

Let's continue this back in the original thread.

> [@Need help inputting CSV data from OBD2 into influx from Chevy bolt](https://discourse.nodered.org/t/need-help-inputting-csv-data-from-obd2-into-influx-from-chevy-bolt/19771/6):
>
> I would like to store all the values with the GPS time stamp for the time So for example Battery Level GPS Time: 1577775035485 !Battery Level Displayed(%): 72.94117737 Battery voltage GPS Time: 1577775035485 !MG Voltage(V): 372.98001099 Ect. All values are from a CSV logfile from the OBD2 reader. The way I have it right now I get a message object for each row in the CSV file with GPS Time being the first line outputted. I need to modify the message to a format that is correct for influ…

---

<div class="post-metadata">

**Author:** ![Nikolay](https://avatars.discourse-cdn.com/v4/letter/n/a698b9/32.png) [@Nikolay](https://discourse.nodered.org/u/Nikolay)\
**Post date:** [13 April 2021 08:10 UTC](https://discourse.nodered.org/t/convert-date-time-to-unix-time/19787/5 "2021-04-13T08:10:23Z")

</div>

I have an array from a database with UNIX/epoch time format and I use this to convert all the timestamps in the array:

var i;  
for (i = 0; i \<msg.payload.length; i++) {

var now = new Date(msg.payload[i].TIMESTAMP).toLocaleString("en-GB");  
msg.payload[i].TIMESTAMP = now;

}

return msg;

So new Date().toLocaleString("en-GB"); works for me.

---

<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:** [13 April 2021 08:25 UTC](https://discourse.nodered.org/t/convert-date-time-to-unix-time/19787/6 "2021-04-13T08:25:46Z")

</div>


