Home > Mobile >  How can I convert UTC dateTime to IST dateTIme in JavaScript
How can I convert UTC dateTime to IST dateTIme in JavaScript

Time:09-23

I am using Microsoft graph API to get the event and in that event Object I am getting the start and end date like this

"start": {
        "dateTime": "2022-09-17T12:00:00.0000000",
        "timeZone": "UTC"
    },
    "end": {
        "dateTime": "2022-09-17T12:20:00.0000000",
        "timeZone": "UTC"
    },

but it is in UTC

in DB I have this start and end DateTime in IST so I want to match the DB event with the events I am getting from Graph API and for that, I am using the DateTime property for that

I am thinking of first converting the graph API events DateTime property into IST formate and then matching it is there any way to do that

CodePudding user response:

var dateUTC = new Date("2022-09-17T12:00:00.0000000");
var dateUTC = dateUTC.getTime() 
var dateIST = new Date(dateUTC);
//date shifting for IST timezone ( 5 hours and 30 minutes)
dateIST.setHours(dateIST.getHours()   5); 
dateIST.setMinutes(dateIST.getMinutes()   30);

CodePudding user response:

I am a signed web developer today and I have great skills in web development. Consider this code snap. I hope this code will help you perfectly.

    `var dateUTC = new Date("1998-01-10T14:00:00.0000000");`
    `var dateUTC = dateUTC.getTime() `
    `var dateIST = new Date(dateUTC);`
    `dateIST.setHours(dateIST.getHours()   15); `
    `dateIST.setMinutes(dateIST.getMinutes()   20);`

Cheers!

  • Related