# UTC to IST time

**URL:** <https://discourse.nodered.org/t/utc-to-ist-time/73948>\
**Category:** General\
**Created:** [20 January 2023 10:22 UTC](https://discourse.nodered.org/t/utc-to-ist-time/73948 "2023-01-20T10:22:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jhankhana](https://avatars.discourse-cdn.com/v4/letter/j/35a633/32.png) [@Jhankhana](https://discourse.nodered.org/u/Jhankhana)\
**Post date:** [20 January 2023 10:22 UTC](https://discourse.nodered.org/t/utc-to-ist-time/73948/1 "2023-01-20T10:22:46Z")

</div>

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.

```auto
[{"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"]]}]

```

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [20 January 2023 11:10 UTC](https://discourse.nodered.org/t/utc-to-ist-time/73948/2 "2023-01-20T11:10:03Z")

</div>

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

```auto
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;

```

---

<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:** [20 January 2023 14:01 UTC](https://discourse.nodered.org/t/utc-to-ist-time/73948/3 "2023-01-20T14:01:54Z")

</div>

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).

---

<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:** [3 February 2023 14:02 UTC](https://discourse.nodered.org/t/utc-to-ist-time/73948/4 "2023-02-03T14:02:49Z")

</div>

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