Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

167
Visualizações
Javascript local datetime into selected timezone

I have https://www.daterangepicker.com/ which outputs some datetimes.

If I am in timezone (device timezone) Europe/Kiev (GMT+3) the outputs will be in those timeszones. For example 27 June 2022 12:00:00 am GMT+3. (midnight) enter image description here

var output = 1656277200000;

I also have the user that selects a timezone for example user selects London (GMT+1).

var timezone = "Europe/London";

I want to convert that output unix time from 27 June 2022 12:00:00 am GMT+3 to the timezone of what the user selected, the London timezone: 27 June 2022 12:00:00 am GMT+1. That means the unix: 1656284400000

enter image description here

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You would have to convert the timezone to an integer representing GMT. Then you subtract your timezone from theirs. You can convert the difference to milliseconds and add it to the original unix time. Example if your timezone is +5 and theirs is +7:

const myTimezone = 5;
const theirTimezone = 7;
const diffarance = theirTimezone - myTimezone; // set to + 2
const differenceMilliseconds = diffarance * 3600000;
const theirUnix = myUnix + differenceMilliseconds;

This also works if the the difference is negative.

about 4 years ago · Juan Pablo Isaza Relatório

0

You can try this way

// Without moment-timezone
new Date().toLocaleString("en-US", { timeZone: "America/New_York" });

// With moment-timezone
var moment = require("moment-timezone");
const today = new Date();
var timeGet = moment(today);
timeGet.tz("Asia/Karachi").format("ha z");
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda