2014-03-27 53 views
0

什麼是應該採取當前時間的AutoIt腳本?如何編寫計算一天中第一次運行的AutoIt腳本?

+1

當然是的;-)你到底想做什麼?你有沒有工作的代碼?在AutoIt中有與時間相關的功能,您可以使用IniWrite或RegWrite來保存一些時間信息。您只需檢查您是否已經在該特定日期節省了時間,並且您可以在第一天首次保存該日期,並從早期日期中刪除所有時間。然後只顯示當天已經保存的時間,每次運行腳本時......不應該是一個長腳本。 – Samoth

+1

你解決了你的問題嗎?然後考慮共享它,以便其他人可以從你的答案中獲得一些價值;-) – Samoth

回答

3

所以這裏有一些基於功能的簡單方法來做你想做的事情。好的是,這樣你就可以很好地格式化你的結果,而且它的重量輕,易於理解。

#include <Date.au3> 

Global $ini = "ini.ini" 

If _AlreadyRunToday() Then 
    MsgBox (0, "Title", _Format(_Diff())) 
Else 
    __SetTime() 
EndIf 
__SetDate() 


Func _AlreadyRunToday() ;Checks if the program run today yet 
    If IniRead($ini, "Section", "D", "") <> @MDay _ 
     Or IniRead($ini, "Section", "M", "") <> @Mon _ 
     Or IniRead($ini, "Section", "Y", "") <> @Year Then Return False 
    Return True 
EndFunc 

Func _ReadDate() ;Returns the time when the program run the first time in YYYY/MM/DD HH:MM:SS 
    Return IniRead($ini, "Section", "Y", "") & "/" & IniRead($ini, "Section", "M", "") & "/" & IniRead($ini, "Section", "D", "") & " " & IniRead($ini, "Section", "H", "") & ":" & IniRead($ini, "Section", "Mi", "") & ":" & IniRead($ini, "Section", "S", "") 
EndFunc 

Func __SetDate() ;Sets the date the program run the last time 
    IniWrite($ini, "Section", "D", @MDay) 
    IniWrite($ini, "Section", "M", @Mon) 
    IniWrite($ini, "Section", "Y", @Year) 
EndFunc 

Func __SetTime() ;Sets the time of the first instance running that day 
    IniWrite($ini, "Section", "H", @Hour) 
    IniWrite($ini, "Section", "Mi", @Min) 
    IniWrite($ini, "Section", "S", @Sec) 
EndFunc 

Func _Diff() ;Calculates the seconds passed since the first run today 
    Return _DateDiff("s", _ReadDate(), _NowCalc()) 
EndFunc 

Func _Format($Seconds) ;Turns seconds to HH:MM:SS 
    Local $h, $m, $s 
    _TicksToTime($Seconds * 1000, $h, $m, $s) 
    ;Return $h & ":" & $m & ":" & $s 
    Return StringFormat("%02d:%02d:%02d", $h, $m, $s) ;As suggested by Samoth 
EndFunc 
+1

所以,你可以刪除你的函數'_2(...)',並用'StringFormat'替換你的'_Format(...)'中的Return語句(「%02d:%02d:%02d」,$ h,$ m,$ s)''。 – Samoth

相關問題