He estado buscando durante horas cómo eliminar GMT de la hora en mi sitio web. Vi muchos temas pero no pude aplicarlos en mi código; Soy novato en JS. Tengo el siguiente código:
var timestamp = '<?=time();?>'; function updateTime() { $('#time').html(Date(timestamp)); timestamp++; } $(function() { setInterval(updateTime, 1000); }); <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> TIME: <span id="time"></span>Lo que me da el siguiente resultado:
HORA: miércoles, 27 de octubre de 2021 00:26:01 GMT+0530 (hora estándar de EE. UU.)
Pero solo quiero:
HORA: miércoles, 27 de octubre de 2021 00:26:01
prueba esto:
$(function() { setInterval(()=> { let d = new Date; $('#time').html(`${d.toDateString()} ${d.toLocaleTimeString()}`); }, 1000); });Utilice String.prototype.substr() . Ver documentos - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr
function updateTime() { $('#time').html(Date().substr(0,25)); } $(function() { setInterval(updateTime, 1000); });