分类: 系统运维
2012-08-12 20:12:35
import win.ui;
import inet.whttp
/*DSG{{*/
var winform = ..win.form( bottom=134;parent=...;right=301;text="取网站时间" )
winform.add(
settimebn={ bottom=118;right=54;left=11;top=90;z=5;text="校正";cls="button" };
edit={ bottom=41;text="";left=22;top=17;z=2;right=282;edge=1;cls="edit" };
gettimebn={ bottom=80;right=55;left=12;top=52;z=4;text="获取";cls="button" };
groupbox={ bottom=49;right=292;left=10;top=3;z=1;text="网址";edge=1;cls="groupbox" };
edit2={ bottom=119;right=289;left=60;multiline=1;top=55;z=3;edge=1;cls="edit" }
)
/*}}*/
url = winform.edit.text
// 取网站时间
getTime = function(url){
var whttp = inet.whttp()
whttp.beginRequest(url,"GET")
whttp.send()
var da = whttp.readHeader("Date")
var tm=time(da,"%a,%d %b %Y %H:%M:%S");
tm.addhour(8)//GMT时间转北京时间
return tm;
}
winform.edit.oncommand = function(id,event){
if(event==0x300/*_EN_CHANGE*/){//文本发生改变了
url = winform.edit.text
}
}
// 获取网站时间
winform.gettimebn.oncommand = function(id,event){
tm = getTime(url)
tm.format="%H时%M分%S秒";
tm1 = time(,"%H时%M分%S秒")
winform.edit2.text = "网站时间:"+tostring(tm)+'\r\n'+ "本机时间:"+tostring(tm1)+'\r\n'
}
//设置时间API 校正时间
SetLocalTime = ::Kernel32.api("SetLocalTime","int(struct lpSystemTime)")
winform.settimebn.oncommand = function(id,event){
var tm = getTime(url)
SetLocalTime(tm);
}
winform.show()
win.loopMessage();