JavaScript获取某个文件的更新时间

JavaScript062

JavaScript获取某个文件的更新时间,第1张

var fso = new ActiveXObject("Scripting.FileSystemObject")

var f1 = fso.GetFile("d:\\test.txt")

alert("File last modified: " + f1.DateLastModified)

给你完整的好了,刚写的,要在D建个test.txt

<html>

<head>

<script language="javascript">

function a(){

var fso = new ActiveXObject("Scripting.FileSystemObject")

var f1 = fso.GetFile("d:\\test.txt")

alert("File last modified: " + f1.DateLastModified)

}

</script>

</head>

<body>

<a href="#" onclick="a()">点击查看效果</a>

</body>

</html>

“修改时间最久的”这一句我没法理解,呵呵O_O!!!

可以用这个属性:fileUpdatedDate

document.getElementById('img_id').fileUpdatedDate// 得到了img元素src所指向图片的最后修改时间,格式:月/日/年

得到了图片最后修改时间,具体使用相信你就知道了。^_^

<script>

function show(){

var date = new Date()//日期对象

var now = ""

now = date.getFullYear()+"年"//读英文就行了

now = now + (date.getMonth()+1)+"月"//取月的时候取的是当前月-1如果想取当前月+1就可以了

now = now + date.getDate()+"日"

now = now + date.getHours()+"时"

now = now + date.getMinutes()+"分"

now = now + date.getSeconds()+"秒"

document.getElementById("now").value = now//input的html是now这个字符串

setTimeout("show()",1000)//设置过1000毫秒就是1秒,调用show方法

}

</script>

<body onLoad="show()"><!-- 网页加载时调用一次 以后就自动调用了-->

<input id="now" type="text" style="width:200pxtext-align:center" />

<!--把需要加载时间的页面元素的id=‘now’,就可以了-->

</body>