How to parse time between timezones

24 Views Asked by At

I have this function:

export const convertTimeByTimezones = ({
  deadlineDateTime,
}) => {
  const res = dayjs("2024-01-16T18:30")
    .tz('America/New-York')
    .tz('Europe/London')
    .format('h:mmA');
  return res; // 4:30PM
};

It should be 23:30

1

There are 1 best solutions below

0
Itay Tur On

Fixed it with the tz method second argument

  const res = dayjs
    .tz(deadlineDateTime, "America/New-York")
    .tz("Europe/London")
    .format('h:mmA');
  return res;