0

I have a timestamp string and a timezone, and I need to convert that into a Date object in UTC without using moment-timezone.

Essentially, I wanna be able to do this without external dependencies:

var date = moment.tz("2021-03-03 14:40:40", "Asia/Dhaka")

Is this possible? I'd rather not have to download a rather hefty package just for this.

mylox
  • 61
  • 5
  • Difficult without a library, but of course the libraries do it with JS so you can too if you're willing. See [*Calculate Timezone offset only for one particular timezone*](https://stackoverflow.com/questions/61361914/calculate-timezone-offset-only-for-one-particular-timezone). – RobG Mar 24 '21 at 01:55

1 Answers1

1

Check it out

let dateString = new Date("2021-03-03 14:40:40").toDateString('en-US', {timeZone: 'Asia/Dhaka'})
console.log(dateString);
Talha Noyon
  • 596
  • 5
  • 12