Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

445
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda