-2

I need to convert UTC time to IST using javascript, the sting is 13:18:30, I have tried to convert this string to IST, but I couldn't do that, if anyone knows the answer or any idea help me to find out the answer.

Bennison J
  • 414
  • 1
  • 12
  • Does this answer your question? [How to convert Date string to a specific time zone](https://stackoverflow.com/questions/58018727/how-to-convert-date-string-to-a-specific-time-zone) – Daniel Beck Aug 24 '22 at 14:24

1 Answers1

-1

You have to use moment js package for this purpose. Here is the example-

import moment from "moment-timezone";

var input = new Date();
var utcTime = moment.utc(input).format();
var istTime = moment(utcTime).tz("Asia/Kolkata").format();

console.log(istTime);
console.log(utcTime);
Asif Jalil
  • 622
  • 5
  • 15
  • 1
    There is no need to use a library, plain JS is sufficient (e..g `new Date().toLocaleString('default',{timeZone:'Asia/Kolkata'})`). There are many alternatives to moment.js. – RobG Aug 24 '22 at 20:45