Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> JavaScript

วิธีแสดงวันที่และเวลาที่เอกสารถูกแก้ไขล่าสุดใน JavaScript

document.lastModified ให้วันที่และเวลาที่เอกสารถูกแก้ไขล่าสุด

ไวยากรณ์

Time = document.lastModified;

ตัวอย่างที่ 1

<html> <body> <script> 
    document.write("This document is lastly modified on " + document.lastModified); 
</script> </body> </html>

ผลลัพธ์

This document is lastly modified on 07/29/2019 15:19:41

ตัวอย่างที่ 2

<html> <body> 
<p>This document was last modified <span id="modify"></span>.</p> 
<script> 
    document.getElementById("modify").innerHTML = document.lastModified; 
</script> </body> </html>

ผลลัพธ์

This document was last modified 07/29/2019 15:26:23.