Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

159
Views
API precisa de fecha y hora del navegador

Supongo que la new Date() nativa del navegador está sujeta a errores en la fecha y hora de la computadora cliente. En mi aplicación actual, sería más fácil si pudiera garantizar que la fecha y hora proporcionada por el navegador de un usuario es aceptablemente precisa (es decir, +/- 3 segundos está bien).

¿Existe una API (a través de solicitudes HTTP) que, cuando se consulta, devuelva la fecha y hora UTC actuales?

No me importa si tienes que registrarte/gastar dinero para usarlo/su tarifa está limitada por el origen.

Estaba imaginando que podría usar el siguiente código:

 let ms_diff: number | undefined = undefined async function get_datetime () { if (ms_diff === undefined) { const start = new Date().getTime() const text = await fetch("https://example.com/current_datetime").text() const end = new Date().getTime() // Perhaps retry once or twice if difference between // `start` and `end` is too large. // approximate datetime of when request was received at API const simple_mean = (start + end) / 2 ms_diff = new Date(text).getTime() - simple_mean } return new Date(new Date().getTime() + ms_diff) }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Encontré uno: http://worldtimeapi.org/pages/examples .

Creo que la API más fácil de implementar es http://worldtimeapi.org/api/ip . Esto es lo que envía:

 { "abbreviation": "PDT", "client_ip": "206.110.20.18", "datetime": "2021-09-13T08:32:18.636090-07:00", "day_of_week": 1, "day_of_year": 256, "dst": true, "dst_from": "2021-03-14T10:00:00+00:00", "dst_offset": 3600, "dst_until": "2021-11-07T09:00:00+00:00", "raw_offset": -28800, "timezone": "America/Los_Angeles", "unixtime": 1631547138, "utc_datetime": "2021-09-13T15:32:18.636090+00:00", "utc_offset": "-07:00", "week_number": 37 }

Advertencia: Esto es lo que dice el sitio web:

No se recomienda que esta API se utilice para aplicaciones comerciales. La API puede caer de vez en cuando, durante períodos relativamente largos. Se proporciona sin SLA, sin garantías y sin financiación directa.

http://worldtimeapi.org/pages/faqs#what-can-i-use-it-for

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!