|
/*
此脚本实现一个记录设备运行时间功能
*/
var fmt = import("fmt")
var time = import("time")
start = GetDeviceData("vm1->status")//启动标志
layout = "15:04:05"
now = time.Now()
now1 = now.Format(layout)
if start == 1 {
time_history_str = toString(GetDeviceData("vm1->time1"))
time_history, _ = time.Parse(layout, time_history_str)
time_now, _ = time.Parse(layout, now1)
time_sub = time_now.Sub(time_history)
time_sub_int = time_sub * 0.000000001
SetDeviceData("vm1->time2",time_sub_int)
//获取累计时间和本次时间
a = GetDeviceData("vm1->time2")
b = GetDeviceData("vm1->time3")
c = a + b
time_out_int = a + 57600
time_out = time.Unix(time_out_int, 0)
timestr = time_out.Format("15:04:05")
SetDeviceData("vm1->time4",timestr)
time_out_int_all = c + 57600
time_out_all = time.Unix(time_out_int_all, 0)
timestr_all = time_out_all.Format("15:04:05")
SetDeviceData("vm1->time5",timestr_all)
} else {
SetDeviceData("vm1->time1",now1)
time_sub_save2_str = GetDeviceData("vm1->time2")
time_sub_save3_str = GetDeviceData("vm1->time3")
time_sub_save = time_sub_save3_str+time_sub_save2_str
SetDeviceData("vm1->time3",time_sub_save)
SetDeviceData("vm1->time2","0")
}
/*
变量说明:
start:计时启动标志
time1:启动前时间,作为参照
time2:单次时间的整数值
time3:累计时间的整数值
time4:单次时间输出
time5:累计时间输出
调试回显:
fmt.Printf("time_sub:%T",time_sub,"\n")
fmt.Printf("time_sub_t:%T",time_sub_t,"\n")
fmt.Printf("time_now:%T",time_now,"\n")
fmt.Printf("time_history_str:%T",time_history_str,"\n")
fmt.Printf("start:%T",start,"\n")
*/ |
|