I've been searching for hours to how remove GMT from time on my website. I saw a lot of topics but couldn't apply them in my code; I'm newbie in JS. I have the following code:
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>
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>
Which give me the following output:
TIME: Wed Oct 27 2021 00:26:01 GMT 0530 (US Standard Time)
But i Want only:
TIME: Wed Oct 27 2021 00:26:01
CodePudding user response:
try this:
$(function() {
setInterval(()=> {
let d = new Date;
$('#time').html(`${d.toDateString()} ${d.toLocaleTimeString()}`);
}, 1000);
});
CodePudding user response:
Use String.prototype.substr()
. See docs - 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);
});