SystemRunStartTime:=GetSystemRunStartTime()
NowTime:=SystemRunStartTime
EnvSub, NowTime, %A_Now%, Seconds
MsgBox % "系统已运行:" FormatSeconds(Abs(NowTime))
;;获取系统开机时间,返回格式同A_Now
GetSystemRunStartTime(){
ClipSaved := ClipboardAll
CommandInfo:=""
try {
Clipboard:=""
Run,% ComSpec " /C net statistics WORKSTATION | CLIP", , Hide
ClipWait
CommandInfo:=Clipboard
}
Clipboard:=ClipSaved
ClipWait
RegExMatch(CommandInfo,"20[\d]{2}(\D\d+){2}\D+\d+(\D\d+){2}",RunTime)
RunTime:=RegExReplace(RegExReplace(RunTime,"(?<=\D)(\d)(\D)|(?<=\D)(\d)$","0$1$2"),"\D")
return StrLen(RunTime)=14?RunTime:""
}
;格式化秒数为中文时间
FormatSeconds(Seconds){
Hour:=Seconds>3600?Seconds//3600:0
Minute:=Hour?(Seconds-Hour*3600)//60:Seconds//60
Second:=Hour||Minute?Seconds-(Hour*3600+Minute*60):Seconds
Return (Hour?Hour "小时":"") (Minute?Minute "分":"") (Second?Second "秒":"")
}
(Seconds-Hour*3600) 这里我用的是mod(seconds,3600),
hour := Seconds>3600?Seconds//3600:0
minutes := hour?mod(Seconds,3600)//60:Seconds//60
second := hour||minutes?mod(mod(Seconds,3600),60):seconds
随便,想到什么用什么?