Set Date YMD
Set Century On
Set Hours To 24
*假定设置系统日期、时间为:2005,01,01
nDate=Ctod('2005/01/01')
oldtime=Time() &&取当前时间,想修改时间,修改此项
*oldtime='17:17:00' &&取当前时间,想修改时间,修改此项
nHo=Val(Substr(oldtime,1,2)) &&取当前时间-时
nSe=Val(Substr(oldtime,4,2)) &&取当前时间-分
nMi=Val(Substr(oldtime,7,2))&&取当前时间-秒
nMM=Val(Right(oldtime,2))&&取当前时间-毫秒
cBuf=h2str(Year(nDate))+h2str(Month(nDate))+h2str(Dow(nDate)-1)+h2str(Day(nDate))+h2str(nHo)+h2str(nSe)+h2str(nMi)+h2str(nMM)
*&&将转换后的二进制字符连接
Declare SHORT SetLocalTime In win32api String SystemTime
SetLocalTime(cBuf) &&设置系统日期
Clear Dlls
Return
Set Century On
Set Date YMD
Set Hours To 24
m.ltDateTime={^2009/01/01 00:00:00} &&要设置的日期时间
m.updtdate = Ttod(m.ltDateTime)
m.updttime = Ttoc(m.ltDateTime,2)
setsystime(m.updtdate, m.updttime)
Function word2str
Parameters m.wordval
Private i, m.retstr
m.retstr = ""
For i = 8 To 0 Step -8
m.retstr = Chr(Int(m.wordval/(2^i))) + m.retstr
m.wordval = Mod(m.wordval, (2^i))
Next
Return m.retstr
Endfunc
*方法四:对方法二的改进(dkfdtf)
NT 以上系统需要先用 AdjustTokenPrivileges 函数给进程赋 SE_SYSTEMTIME_NAME 权限
如果对这些 api 的使用不熟悉,用 WinExec 等高级些的 api 也可以:
Declare Long WinExec In WIN32API String, Long
WinExec('cmd /c date 2009/06/05',0) &&设置系统日期
WinExec('cmd /c time 09:00:00',0) &&设置系统时间
不过上面这个仍是使用 date 操作系统内部命令来修改日期的,与 run | ! 命令使用的是相似的方法,唯一不同的是它不显示那个黑色的 dos 窗口。但也因此需要根据不同的操作系统使用不同的命令,例如,win9x/me 中就需要将 cmd 改为 command
如:
m.ltDateTime={^2009/01/01 00:00:00} &&要设置的日期时间
Declare Long WinExec In WIN32API String, Long
WinExec('cmd /c date '+Dtoc(Ttod(m.ltDateTime)),0) &&设置系统日期
WinExec('cmd /c time '+Ttoc(m.ltDateTime,2),0) &&设置系统时间