document.lastModified只显示当前日期?

时间:2017-06-13 08:45:04

标签: javascript

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

现在我一直在搜索,并且所有内容都指向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年的技术课程?

Press here to see the scripts live

1 个答案:

答案 0 :(得分:1)

因为您正在修改它。例如,检查一下。

要根据您的要求开展此项工作,请结帐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("");