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

524
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 馃檪

over 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;
over 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
Asistente virtual