我有一个带有文件系统的 javascript 程序(保存用户答案等)我已经实现了数据和时间的文件名但是如果用户重复该程序,然后结束它。所有文件将同时保存
尝试将其放入字符串中。文件系统完成工作后,我清除字符串。哪个应该工作?因为它将检查新的本地时间。
function filesystem() {
var date = today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + today.getDate(); //gets local machine year,date,time.
var time = today.getHours() + "Hour." + today.getMinutes() + " Min." + today.getSeconds() + " Seconds";
var dateTime = parseFloat("Date " + date + ' ' + "Time " + time);
var dateTimestr= "";
dateTimestr += (dateTime);
fs.writeFile("CA2/Quizresults/" + fullname + " " + categorystorage + " " + dateTimestr + ".txt", summarystring + "Your score is " + point + "/5.", (err) => {
if (err) throw err;
})
console.log('Saved!'); //when saved successfully. it will prompt the user.
point = 0; //Sets point as 0. so the point does not bring forward to the next user.
lifelinecounter = 0; //Sets lifelinecounter as 0. so the lifelinecounter does not bring forward to the next user.
summarystring = "";
dateTimestr =""; //Sets summarystring as empty. so the summarystring does not bring forward to the next user.
}
所有文件在文件名中保存相同的时间
最佳答案
var today = new Date();
请将以上添加为函数的第一条语句。您已在函数外分配了今天,并且它的值不会根据运行时间而改变。如果您想要当前日期,则必须再次调用 new Date() 并将其分配给今天的变量。
关于javascript - 文件系统同时保存所有文件名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57336360/