我已经搜索了几个小时,如何删除格林尼治时间在我的网站上。我看到了很多主题,但无法在我的代码中应用;我是JS的新手。我有以下代码:
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>
这给了我以下的输出:
时间:2021年10月27日星期三GMT+0530 (美国标准时间)26:01
但我只想:
时间:10月27日星期三2021 00:26:01
发布于 2021-10-26 21:31:48
试试这个:
$(function() {
setInterval(()=> {
let d = new Date;
$('#time').html(`${d.toDateString()} ${d.toLocaleTimeString()}`);
}, 1000);
});发布于 2021-10-26 21:28:03
使用String.prototype.substr()。见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);
});https://stackoverflow.com/questions/69729973
复制相似问题