简体   繁体   中英

How can I convert UTC dateTime to IST dateTIme in JavaScript

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

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

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM