JSFiddle - React, Tailwind, and code Playground
Write a code that fetches the hour from the Internet and shows it.
by Porfirio Chavez
HTML
<div class="result">
</div>
<button>
Actualizar
</button>
JavaScript
$(function(){
var url = "https://api.timezonedb.com/?zone=America/Mexico_City&format=json&key=ICPRZPXC6BDL";
var resultDiv = $('.result');
var boton = $('button');
function obtenerHora(){
boton.prop("disabled", true);
var request = $.get(url);
request.done(function(data) {
var fecha = new Date(data.timestamp * 1000);
fechalegible = fecha.toGMTString();
resultDiv.html("Zona: " + data.zoneName + " <br> Fecha: " + fechalegible);
boton.prop("disabled", false);
})
.fail(function(data) {
alert('error');
boton.prop("disabled", false);
console.error(data);
});
}
$('button').on('click', obtenerHora);
obtenerHora();
});