UTC to IST time

I want to display Current time according to IST. I have done plus 5 in hours and 30 in min. but It's not the solution as it will do +5 when time is 23 also and +30 when min is already 60.
Pleas guide me with this.

I am trying to pass on date and time in different column of the table.

[{"id":"425b8a.987c8478","type":"debug","z":"34503490.74c53c","name":"","active":true,"console":"false","xaxis":"_time","complete":"false","x":1490,"y":560,"wires":[]},{"id":"6d6b5a1c.351ee4","type":"function","z":"34503490.74c53c","name":"","func":"var dateUTC = new Date();\nlet day = dateUTC.getDate();\nlet month =dateUTC.getMonth() + 1;\nlet year = dateUTC.getFullYear();\n\n\n//date shifting for IST timezone (+5 hours and 30 minutes)\nlet hour = dateUTC.getHours() + 5; \nlet min= dateUTC.getMinutes() + 30;\nlet sec = dateUTC.getSeconds();\n\nlet printdate = `${day}-${month}-${year}`;\nlet printtime = `${hour}:${min}:${sec}`; \n\n\n\nmsg.payload = [\n    {\n        \"Date\": printdate,  \n        \"Time\": printtime,\n    },\n  ];\n  return msg;\n","outputs":1,"language":"javascript","noerr":0,"x":1320,"y":560,"wires":[["425b8a.987c8478"]],"_type":"node"},{"id":"d59e0171.98ced","type":"inject","z":"34503490.74c53c","name":"","topic":"","payload":"","payloadType":"date","repeat":"","repeatEnd":"0","endTime":"0","crontab":"","offset":"0","once":false,"properties":"","timezone":"utc","betweentimesunit":"m","enableRuleEngine":false,"showNextExecution":false,"powerMode":false,"x":1120,"y":560,"wires":[["6d6b5a1c.351ee4"]]}]

You can use setHours() and setMinutes()
e.g

const dateUTC = new Date();
let day = dateUTC.getDate();
let month =dateUTC.getMonth() + 1;
let year = dateUTC.getFullYear();


//date shifting for IST timezone (+5 hours and 30 minutes)
dateUTC.setHours(dateUTC.getHours() + 5);
dateUTC.setMinutes(dateUTC.getMinutes() + 30);
let hour = dateUTC.getHours();
let min= dateUTC.getMinutes();
let sec = dateUTC.getSeconds();

let printdate = `${day}-${month}-${year}`;
let printtime = `${hour}:${min}:${sec}`; 



msg.payload = [
    {
        "Date": printdate,  
        "Time": printtime,
    },
  ];
  return msg;

You should not do timezone calculations manually. They will almost certainly fail for certain edge-cases.

Either use Moment which is available in a contrib node or within JSONata (e.g. the change or function nodes) or grab a reference to node.js's INTL library which is a JavaScript standard (see MDN for details).

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