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

236
Visualizações
how can I get a list of all countries together with their time using moment js?
 const timezone = moment.tz.names();
  const timezoneList = [];

  timezone.forEach((element) => {
    timezoneList.push({ label: element, value: element });
  });

At the moment I am just getting the list but I am trying to get also the local time of each country together.

Thank you very much

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

0

I'd suggest having a look at countries-and-timezones, this has a very convenient list of countries along with their timezones.

Once we have a country's list of timezones we can get the local time(s), using Date.toLocaleTimeString() allowing us to log local times for each country.

I've done this for the first 20 countries below:

let countries = Object.values(ct.getAllCountries()).sort(({ name: a}, { name: b}) => a.localeCompare(b)).slice(0,20);
console.log('Country'.padEnd(20), 'Local Time(s):')

for(let country of countries) {
    console.log(country.name.padEnd(20), getLocaleTimes(country.timezones).join(", "))
}

function getLocaleTimes(timeZones) {
    return [...new Set(timeZones.map(getLocalTime))];
}

function getLocalTime(timeZone) {
    return new Date().toLocaleTimeString([], { timeZone, });
}
.as-console-wrapper { max-height: 100% !important; top: 0; }
<script src="https://cdn.jsdelivr.net/gh/manuelmhtr/countries-and-timezones@latest/dist/index.min.js" type="text/javascript"></script>

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