// ==========================================================================
// 获取当前时刻, 并计算时间戳(起点:UT8-2000.01.01 00:00:00)
// ==========================================================================
sub int GetTimeStamp()
// bool ON = true, OFF = false
// unsigned short MonDat[12]={31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
unsigned short LcDat[6], MonDat[13]={00, 31, 59, 90,120,151,181,212,243,273,304,334,365}
unsigned int tps, tpa, tpb, tpc, tpd
// tmStamp = 757382400 //TEST:24.01.01 00:00:00
// ==========================================================================
GetData(LcDat[0], "Local HMI", LW, 9017, 6) //_读当前时刻
tpa = LcDat[5] -2000 //年(时间戳计算)
tpb = LcDat[4] -1 //月
tpc = LcDat[2] //时
tpd = tpa*1461/4 + MonDat[tpb] +LcDat[3] -1 //经历天数统计(含闰年)
if tpa %4 <> 0 or tpb >=2 then //闰年补天修正
tpd = tpd +1
end if
tpc = tpc*3600 +LcDat[1]*60 +LcDat[0] //不足一天的总秒统计
tps = tpd*86400 + tpc //秒计时间戳 TimeStamp of Sec
// ==========================================================================
return tps
end sub
|