-2

need to replace GMT+0530 (India Standard Time) to IST dynamically for multiple array list

for now my array list has 6 entries. need to replace for all the array list .

function getTimeAccordingtoTimeZone(utc){
    utc  = new Date(Date.parse(utc));
    var dateUTC = utc ;
    var dateIST = new Date(dateUTC);
    //date shifting for IST timezone (+5 hours and 30 minutes)
    var current_time_zone = getCurrentTimeZone();
    var hour_diff = parseInt(current_time_zone);
    var minute_diff = current_time_zone - hour_diff;
    minute_diff = minute_diff*60;
    dateIST.setHours(dateIST.getHours() + hour_diff);
    dateIST.setMinutes(dateIST.getMinutes() + minute_diff);
    var new_date = dateIST;
    return new_date;
}
new_date returns
Tue Jan 15 2019 22:49:04 GMT+0530 (India Standard Time)
Tue Jan 15 2019 22:49:04 GMT+0530 (India Standard Time)
Tue Jan 15 2019 22:49:04 GMT+0530 (India Standard Time)
Tue Jan 15 2019 22:49:04 GMT+0530 (India Standard Time)
Tue Jan 15 2019 22:49:04 GMT+0530 (India Standard Time)
Tue Jan 15 2019 22:49:04 GMT+0530 (India Standard Time)

  • You want to convert IST to UTC? – Stefan Hariton Jan 18 '19 at 07:55
  • 4
    Possible duplicate of [Convert date to another timezone in JavaScript](https://stackoverflow.com/questions/10087819/convert-date-to-another-timezone-in-javascript) – jpeg Jan 18 '19 at 07:55
  • Use a loop to iterate over your array and call the conversion function for each value, what exactly is your problem here? – empiric Jan 18 '19 at 08:24
  • @StefanHariton it is already converted to IST. just need to replace the words to IST because the word India standard time is too long – Khelawan Verma Jan 18 '19 at 11:36

1 Answers1

0

I'd propose you use moment JS to format the string.

In your case, the following code will help you:

const moment = require('moment');
date = moment();
const dateString = `${date.format('ddd MMM DD YYYY HH:mm:ss')} IST`
console.log(dateString);

MomentJs Documentation

Stefan Hariton
  • 347
  • 4
  • 19