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

447
Visualizações
How can I obtain the date based on geographical coordinates? (JavaScript)

I am making a weather application, and I have a simple P-tag which is populated with the date using JavaScript:

HTML:

<p id="date"></p>

JavaScript:

function getDate() {
    var shortDate = document.getElementById("date");
    var today = new Date().toLocaleDateString(undefined, {
        weekday: "long",
        month: "long",
        day: "numeric"
    });
    shortDate.innerHTML = today;
}

My issue is that it always presents the date where I am (which is understandable). Though when I physically change the latitude and longitude to locations with a different date in my JavaScript (such as Australia), it still uses the date where I am, and not that of the coordinates I have amended for the purpose of testing this.

I'm still learning JavaScript, but how can I overcome this to ensure my program uses the date of the different location? Or even using the timezone of the location? When I amended my JavaScript to Australia coordinate, it didn't show the date in Australia!

Thank you 🙂

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

0

I answered my own question! I had to use the offset provided by the API and multiply by 1000 🙂

let today = new Date(Date.now() + offset * 1000).toLocaleDateString(undefined, {
    weekday: "long",
    month: "long",
    day: "numeric"
    });

shortDate.innerHTML = today;
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