0

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> 

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

Mister Jojo
  • 20,093
  • 6
  • 21
  • 40
  • 1
    Does this answer your question? [Parse date without timezone javascript](https://stackoverflow.com/questions/17545708/parse-date-without-timezone-javascript) – B001ᛦ Oct 26 '21 at 21:11
  • use `let a= "TIME: Wed Oct 27 2021 00:26:01 GMT+0530 (US Standard Time)" ; a.substr(0,30)` – Alok Prakash Oct 26 '21 at 21:15
  • BOO1 where exactly should i insert them in my code? and increment is for making it real-time and showing the seconds changing every 1 second – God of data Oct 26 '21 at 21:16
  • @AlokPrakash can you please show me where to add them and remove which part of my code? – God of data Oct 26 '21 at 21:22
  • You can use [moment js](https://momentjs.com/) to get what you want pls do check it out – Nazehs Oct 27 '21 at 01:05

2 Answers2

0

try this:

$(function() {
    setInterval(()=> {
        let d = new Date;
        $('#time').html(`${d.toDateString()} ${d.toLocaleTimeString()}`);
    }, 1000);
});
tdjprog
  • 706
  • 6
  • 11
-1

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);
});
Alok Prakash
  • 191
  • 1
  • 9
  • 1
    thank you, I think the @tdjprog method looks more standard, as the total number of characters that should be removed, might need to be changed in different time zones. – God of data Oct 26 '21 at 21:35