VFP调整本机日期时间与服务器日期时间一致

*!*调整本机日期时间与服务器日期时间一致( YYYY-MM-DD HH:MM:SS.FFF )
*!*以下cSqlStr及nCon为SQL查询串及连接句柄
cSqlStr="Select SysTime=Convert(Char,GetDate(),121)"      &&取服务器本地当前日期时间(已转换为字符型)
=SQLEXEC(nCon,cSqlStr,"SysDateTime")
SELECT SysDateTime
lcDateTime=ALLTRIM(SysDateTime.SysTime)
USE in "SysDateTime"
nYear=VAL(SUBSTR(lcDateTime,1,4))              &&取当前日期-年
nMonth=VAL(SUBSTR(lcDateTime,6,2))             &&取当前日期-月
nWeek=DOW(CTOT(lcdateTime))-1                  &&取当前日期-星期, 实际上此值可为1-7任意间的任意数
nDay=VAL(SUBSTR(lcDateTime,9,2))               &&取当前日期-日
nHours=VAL(SUBSTR(lcDateTime,12,2))            &&取当前时间-时
nMinutes=VAL(SUBSTR(lcDateTime,15,2))          &&取当前时间-分
nSeconds=VAL(SUBSTR(lcDateTime,18,2))          &&取当前时间-秒
nMSeconds=VAL(RIGHT(lcDateTime,3))             &&取当前时间-毫秒
*!*转换十进制数字为二进制字符(高低位互换、压缩)
lcDateBuf=Dec2Binstr(nYear)+Dec2Binstr(nMonth)+Dec2Binstr(nWeek)+Dec2Binstr(nDAY)
lcDateBuf=lcDateBuf+Dec2Binstr(nHours)+Dec2Binstr(nMinutes)+Dec2Binstr(nSeconds)+Dec2Binstr(nMSeconds)
*!*设置本机当地时间
DECLARE SHORT SetLocalTime IN win32api STRING SystemTime
=SetLocalTime(lcDateBuf)                      &&设置本机本地日期时间

*!*将十进制字符转换为二进制
FUNCTION Dec2Binstr
PARAMETERS DecStr
PRIVATE BinStr
BinStr=CHR(MOD(DecStr,256))+CHR(DecStr/256)
RETURN BinStr

猜你喜欢

转载自www.cnblogs.com/hnllhq/p/12306578.html