Conversion of time zone from EST to IST using java script

11,894

Have a good look at the mdn docs for the Javascript Date api.

You can change the hours with setHours. Since IST is 9:30 hours ahead of EST, you just need to substract. You can get IST and EST by calculating them from UTC, Date.getTime() generates a UTC unix timecode. Here's an example

var UTC = new Date();
var UTC = UTC.getTime() // Get UTC Timestamp

var IST = new Date(date); // Clone UTC Timestamp
IST.setHours(IST.getHours() + 5); // set Hours to 5 hours later
IST.setMinutes(IST.getMinutes() + 30); // set Minutes to be 30 minutes later

var EST = new Date(date); // Clone date
EST.setHours(EST.getHours() - 4); // set EST to be 4 hour earlier

Generally, the Date object is a pain to deal with. Thankfully, there's this genius library called moment.js that can help dealing with dates.

Share:
11,894
nilkash
Author by

nilkash

Updated on June 25, 2022

Comments

  • nilkash
    nilkash almost 2 years

    Hi I am developing small web application in which i want to convert my EST time to IST time zone. I know offset value for IST time format and I am having proper time format with correct time as well. But I am not having any idea regarding this conversion.

    How to convert time from EST time zone to IST? Need Help. Thank you.