No announcement yet.

Date format & Time in local time zone, not Zulu time

  • Filter
  • Time
  • Show
Clear All
new posts

    Date format & Time in local time zone, not Zulu time

    I am trying to construct a comma delimited string (msg.payload) and writing it into a CSV file when an event happens. What I am getting is not my local time, but Zulu time and I'm not sure why.

    Here's what I'm doing:

    var d = new Date();
    var t = d.getTime("hh:mm:ss");
    payload={"date":d,"payload":msg.payload,"Source":"BlueIris Geofence","Action":"Light Status Change"};

    return msg;

    Here is what I'm getting:


    """2022-06-02T23:55:00.142Z""",HOME,BlueIris Geofence,Light Status Change

    How do I get the date / time format to be mm/dd/yyyy hh:mm:ss (in EST)?

    If you must use a function node, read this overview on withing with time. Personally, I would use the moment contrib to set the date/time and a Change node to set the rest of your msg object. There is a reason the Moment.js library was created.
    Karl S
    HS4Pro on Windows 10
    1070 Devices
    56 Z-Wave Nodes
    104 Events
    HSTouch Clients: 3 Android, 1 iOS
    Google Home: 3 Mini units, 1 Pair Audios, 2 Displays


      Right off the bat, ksum has the best suggestion. Time related problems are the reasons helper libraries exist.

      That said,

      In your sample snippet, you are setting up variable 't' but never using it... you are using 'd'. I do not think the getTime() works the way you want it to.

      There are plenty of how-to's out there if you search for javascript or nodered date()