-1

I need to schedule a job daily at 1:30 AM, Here 1:30 AM is Timezone dependent.

For Example:
America/Chicago - 1:30 AM output should be GMT 06:30.
Asia/Kolkata - 1:30 AM output should be GMT 20:00.
Asia/Kabul - 1:30 AM output should be GMT 21:00

I want to create a function that will take Timezone (America/Chicago) and Base Time (1:30) as input and output should be 06:30 in GMT

Gurudeepak
  • 372
  • 2
  • 14
  • You need the date as well as location in order to determine the correct offset as daylight saving may or may not be in effect. You should parse the string per the duplicate, i.e. include the format of the string to parse. – RobG May 27 '21 at 02:47
  • @RobG, So the answer which I posted below is correct, or do I need to modify anything? – Gurudeepak May 27 '21 at 08:23

1 Answers1

0

// const moment = reqimpuire("moment-timezone");

function toTimeZone(zone) {
  const time = moment.tz("2013-11-18 01:30:00", zone);
  const utc = moment.utc(time).format();
  console.log(utc);
}
toTimeZone("Africa/Tripoli");
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.9.0/moment-with-locales.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.9/moment-timezone-with-data.min.js"></script>

I solved the problem using the above code.

RobG
  • 142,382
  • 31
  • 172
  • 209
Gurudeepak
  • 372
  • 2
  • 14