gpt4 book ai didi

javascript - 新的时间戳都是同一个日期

转载 作者:太空宇宙 更新时间:2023-11-04 10:01:36 24 4
gpt4 key购买 nike

当显示新任务 (obj) 时,我试图在页面上打印当前日期作为时间戳,但无论何时创建时间戳,新时间戳都是相同的日期。任何帮助将不胜感激。

 function getDate() {
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth() + 1;
var yyyy = today.getFullYear();
var time = today.getTime();
if (dd < 10) {
dd = '0' + dd
}

if (mm < 10) {
mm = '0' + mm
}

today = mm + '/' + dd + '/' + yyyy + ' ' + time;

localStorage.setItem('newDate', today);
var newDate = localStorage.getItem('newDate');
return (newDate);
}

function show() {
var todos = get_todos();
var date = localStorage.getItem('newDate');
var html = '<table>';
for (var i = 0; i < todos.length; i++) {
html += '<br><tr><strong>' +
'<input type="image" src="Pictures/remove.png" class="remove" id="' + i +
'"></input>' + todos[i] + ' - ' + date + '</strong><input type="checkbox" name="cBox" id="isDone"><label for="cBox"</label></tr><br>';
};
html += '</table>';


document.getElementById('todos').innerHTML = html;

var buttons = document.getElementsByClassName('remove');
for (var i = 0; i < buttons.length; i++) {
buttons[i].addEventListener('click', remove);
};
}

document.getElementById('add').addEventListener('click', add);
show();

最佳答案

var date = localStorage.getItem('newDate');

我觉得应该是

var date = getDate();

关于javascript - 新的时间戳都是同一个日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38298306/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com