gpt4 book ai didi

javascript - document.lastModified 只显示当前日期?

转载 作者:行者123 更新时间:2023-12-03 04:06:47 35 4
gpt4 key购买 nike

我一直在寻找一种方法来显示页面上次更新的日期。

现在我一直在搜索,所有内容都指向 document.lastModified 函数,但无论我如何尝试修复它,它总是显示当前日期。

我尝试过这个例子:

function lastModified() { 
var modiDate = new Date(document.lastModified);
var showAs = modiDate.getDate() + "-" + (modiDate.getMonth() + 1) + "-" + modiDate.getFullYear();
return showAs
}
function GetTime() {
var modiDate = new Date();
var Seconds

if (modiDate.getSeconds() < 10) {
Seconds = "0" + modiDate.getSeconds(); }
else {
Seconds = modiDate.getSeconds(); }
var modiDate = new Date();
var CurTime = modiDate.getHours() + ":" + modiDate.getMinutes() + ":" + Seconds
return CurTime }

document.write("Last updated on ");
document.write(lastModified() + " @ " + GetTime());
document.write(" [D M Y 24 Hour Clock]"); document.write("");

或者像这样的简单的:

<SCRIPT LANGUAGE="JavaScript"> 
var t = new Date(document.lastModified);
document.write("<I>Last Updated: "+document.lastModified+"</I><BR>");
document.write("<I>Last Updated: "+t+"</I><BR>");
</SCRIPT>

还有其他方法可以做到这一点吗?.. 没有参加 3 年技术类(class)?

Press here to see the scripts live

最佳答案

因为您当前正在修改它。例如,看看这个。

要根据您的要求进行此操作,请查看 this linkthis link

检查这个会对你有帮助将其放在页面底部:

<script type="text/javascript" src="js_lus.js"></script>
Name the file whatever you want. Example: js_lus.js Make sure src=""
path is correct for all your pages.
function lastModified() {
var modiDate = new Date(document.lastModified);
var showAs = modiDate.getDate() + "-" + (modiDate.getMonth() + 1) + "-" +
modiDate.getFullYear();
return showAs
}

function GetTime() {
var modiDate = new Date();
var Seconds

if (modiDate.getSeconds() < 10) {
Seconds = "0" + modiDate.getSeconds();
} else {
Seconds = modiDate.getSeconds();
}

var modiDate = new Date();
var CurTime = modiDate.getHours() + ":" + modiDate.getMinutes() + ":" + Seconds
return CurTime
}

document.write("Last updated on ")
document.write(lastModified() + " @ " + GetTime());
document.write(" [D M Y 24 Hour Clock]")
document.write("");

关于javascript - document.lastModified 只显示当前日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44516479/

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