//这是一段在网上找到的系统时间自动更新JS脚本,任意Web服务器都可以用来协对时间而且也不用vb来改时间,保存为*.js点击运行即可
//get HTTP Date: response from server, return approximate dateVal object
function getServerDate(serverHttpAddress, httpProxyAddress)
{
var xmlHttp = new ActiveXObject("msxml2.xmlhttp");
if(httpProxyAddress)
{
setProxy(2,proxyHttpAddress.replace("http://",""));
}
xmlHttp.open("GET", serverHttpAddress, 0);
ts=(new Date()).getTime();
WScript.Echo("Start time: " + ts);
xmlHttp.send();
tr=new Date();
WScript.Echo("End time: " + tr.getTime());
WScript.Echo("Server Time: " + Date.parse( xmlHttp.getResponseHeader('Date')));
//Thu, 1 Jan 2009 09:47:01 GMT
tr.setTime(Date.parse( xmlHttp.getResponseHeader('Date')) + ((new Date()).getTime() - ts)/2);
//1230805540107
WScript.Echo("debug time: " + tr)
return tr;
//}
//catch(e)
//{
// return 0
//}
}
//set system time to dateString
//http://www.microsoft.com/technet/scriptcenter/topics/networking/08_atnc_advanced.mspx
//http://www.microsoft.com/technet/scriptcenter/guide/sas_wmi_fvwp.mspx?mfr=true
//20030327073509.519000+480
function setSystemDate(dateString)
{
WScript.Echo("End time: " + dateString);
var oSvc = GetObject("winmgmts:\\\\.\\root\\cimv2");
oSvc.Security_.Privileges.AddAsString("SeSystemTimePrivilege", 1);
var e = new Enumerator(oSvc.execQuery("select * from win32_OperatingSystem", "WQL", 32));
//for (;!e.atEnd();e.moveNext())e.item().SetDateTime(dateString);
}
//generating the right WMI DATETIME fields
with(getServerDate("http://www.google.com/")) //和哪一个HTTP服务器进行同步
{
setSystemDate("" +
getUTCFullYear() +
(getUTCMonth()<9?"0"&#43;(getUTCMonth()&#43;1):(getUTCMonth()&#43;1)) &#43;
(getUTCDate()<9?"0"&#43;getUTCDate():getUTCDate()) &#43;
(getUTCHours()<9?"0"&#43;getUTCHours():getUTCHours()) &#43;
(getUTCMinutes()<9?"0"&#43;getUTCMinutes():getUTCMinutes()) &#43;
(getUTCSeconds()<9?"0"&#43;getUTCSeconds():getUTCSeconds()) &#43;
".******&#43;***");
}