最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Conversion of time zone from EST to IST using java script - Stack Overflow

programmeradmin2浏览0评论

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
Add a ment  | 

1 Answer 1

Reset to default 3

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.

发布评论

评论列表(0)

  1. 暂无评论