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.
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.
Share Improve this question asked May 29, 2013 at 4:57 nilkashnilkash 7,54633 gold badges103 silver badges183 bronze badges 1-
1
Well , you need to get the current time and add or subtract the offset from it.Be wary though ,
JavaScript
date object returns your system time,not the EST. – Harsha Venkataramu Commented May 29, 2013 at 5:15
1 Answer
Reset to default 3Have 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.