admin管理员组文章数量:1400007
I want to show the last updated (modified) time in my website. How can I do it in html. This is my script
<!DOCTYPE html>
<html>
<body>
This is last updated time
<body onload="myFunction()">
<script>
function myFunction() {
var x = document.lastModified;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
I want to show the last updated (modified) time in my website. How can I do it in html. This is my script
<!DOCTYPE html>
<html>
<body>
This is last updated time
<body onload="myFunction()">
<script>
function myFunction() {
var x = document.lastModified;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
Share
Improve this question
asked Sep 9, 2019 at 16:05
KimHeeKimHee
7883 gold badges13 silver badges25 bronze badges
3
- It's unclear if you are asking how to do this without JS or if you want to know why this code isn't working (in which case the error message in the content should be a big clue). What element are you trying to get by its ID? – Quentin Commented Sep 9, 2019 at 16:08
-
It also appears, that
document.lastModified
returns only the current date and time when retrieved on a web page. – Teemu Commented Sep 9, 2019 at 16:13 - Your html is not well formed, so your question is really weird. – iguypouf Commented Sep 9, 2019 at 16:13
3 Answers
Reset to default 4You can use the date object and then use ISOString method,the use substr to get the time from the string
function myFunction() {
var x = document.lastModified;
document.getElementById("demo").innerHTML = new Date(document.lastModified).toISOString().substr(11, 8);
}
myFunction()
This is last updated time <span id='demo'></span>
First you have 2 bodys, dont want that.. then you just need to add the #demo
element to select and innerHTML the lastModified value.
<!DOCTYPE html>
<html>
<body onload="myFunction()">
This is last updated time <span id="demo"></span>
<script>
function myFunction() {
var x = document.lastModified;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
As Requested, All you needed was a div element with id "demo"
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script>
function loadTime() {
document.getElementById("demo").innerHTML = document.lastModified;
}
</script>
</head>
<body onload="loadTime();">
<div id="demo"></div>
</body>
</html>
本文标签: javascriptHow to display the last update time in htmlStack Overflow
版权声明:本文标题:javascript - How to display the last update time in html? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744207967a2595283.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论