Moderators SmOke_N Posted January 29, 2007 Moderators Posted January 29, 2007 (edited) Messing around with something else, I accidentally came up with this for system restart time... to be honest, I hadn't even tested its accuracy. I didn't need it, but it may come in handy for someone else. It returns an array: [1] = Weeks [2] = Days [3] = Hours [4] = Minutes [5] = Seconds #include <array.au3> $aArray = _TimeSystemRestart() _ArrayDisplay($aArray, 'Return Info') Func _TimeSystemRestart() Local $iSubTotal = DllCall('kernel32.dll', 'int', 'GetTickCount') If Not IsArray($iSubTotal) Then Return SetError(1, 0, 0) $iSubTotal = $iSubTotal[0] / 1000 Local $iWeek = Int(($iSubTotal / 604800)) If $iWeek > 0 Then $iSubTotal -= $iWeek * 604800 Local $iDay = Int(($iSubTotal / 86400)) If $iDay > 0 Then $iSubTotal -= $iDay * 86400 Local $iHour = Int(($iSubTotal / 3600)) Local $iMin = Int(($iSubTotal - ($iHour * 3600)) / 60) Local $iSec = Int(($iSubTotal - $iHour * 3600) - ($iMin * 60)) Return StringSplit(StringFormat('%02d', $iWeek) & ':' & $iDay & ':' & StringFormat('%02d', $iHour) & ':' & _ StringFormat('%02d', $iMin) & ':' & StringFormat('%02d', $iSec), ':') EndFunc Edited January 29, 2007 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
NELyon Posted January 29, 2007 Posted January 29, 2007 Very cool. Here's one use i thought of for it: Restricting PC time. When the Hours/Minutes reaches a certain time, lock the Workstation and run it as a service.
_Kurt Posted January 30, 2007 Posted January 30, 2007 Messing around with something else, I accidentally came up with this for system restart time... to be honest, I hadn't even tested its accuracy. I didn't need it, but it may come in handy for someone else. It returns an array: [1] = Weeks [2] = Days [3] = Hours [4] = Minutes [5] = Seconds ;SNIPPEDThis is actually pretty cool, I think it's accurate (tested, and seemed asthough it was correct). @D-Generation X, that sounds like a really nice idea. Kurt Awaiting Diablo III..
PsaltyDS Posted October 21, 2007 Posted October 21, 2007 A General Support user was looking for reformatting of the output, and since the output is already going through a lot of formatting, I did a mod to give different formats out on an input flag: 0 = array, 1 = integer, 2 = string: expandcollapse popup#include <array.au3> ; Default ($iFlag = 0) $aArray = _TimeSystemRestart() _ArrayDisplay($aArray, 'Return Info') ; $iFlag = 1 $iTime = _TimeSystemRestart(1) MsgBox(64, "Return Info", $iTime & " millisecs") ; $iFlag = 2 $sTime = _TimeSystemRestart(2) MsgBox(64, "Return Info", "Uptime: " & $sTime) ; ========================================================================= ; Function _TimeSystemRestart() ; Returns system up time ; $iFlag: ; 0 (default) Returns array: ; [0] = 5; [1] = Wks; [2] = Days; [3] = Hrs; [4] = Mins; [5] = Secs ; 1 Returns integer raw ticks (total millisecs) ; 2 Returns string formatted WW:DD:HH:MM:SS ; Authors: Function by SmOke_N, mod by PsaltyDS ; ========================================================================= Func _TimeSystemRestart($iFlag = 0) Local $iSubTotal = DllCall('kernel32.dll', 'int', 'GetTickCount') If Not IsArray($iSubTotal) Then Return SetError(1, 0, 0) If $iFlag = 1 Then Return $iSubTotal[0] $iSubTotal = $iSubTotal[0] / 1000 Local $iWeek = Int(($iSubTotal / 604800)) If $iWeek > 0 Then $iSubTotal -= $iWeek * 604800 Local $iDay = Int(($iSubTotal / 86400)) If $iDay > 0 Then $iSubTotal -= $iDay * 86400 Local $iHour = Int(($iSubTotal / 3600)) Local $iMin = Int(($iSubTotal - ($iHour * 3600)) / 60) Local $iSec = Int(($iSubTotal - $iHour * 3600) - ($iMin * 60)) Local $sRET = StringFormat('%02d', $iWeek) & ':' & $iDay & ':' & StringFormat('%02d', $iHour) & ':' & _ StringFormat('%02d', $iMin) & ':' & StringFormat('%02d', $iSec) If $iFlag = 2 Then Return $sRET Return StringSplit($sRET, ':') EndFunc ;==>_TimeSystemRestart Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Moderators SmOke_N Posted May 17, 2010 Author Moderators Posted May 17, 2010 (edited) Someone needed something to get time since last restart in a day format. Here you'll see the option for: yyyy/mm/dd hh:mm:ss (24 hour format) mm/dd/yyyy hh:mm:ss (24 hour format) yyyy/mm/dd hh:mm:ss (12 hour format) mm/dd/yyyy hh:mm:ss (12 hour format) expandcollapse popupConsoleWrite(_Date_GetLastRestart() & @CRLF) ConsoleWrite(_Date_GetLastRestart("mm/dd/yyyy", 24) & @CRLF) ConsoleWrite(_Date_GetLastRestart("yyyy/mm/dd", 12) & @CRLF) ConsoleWrite(_Date_GetLastRestart("mm/dd/yyyy", 12) & @CRLF) Func _Date_GetLastRestart($s_type = -1, $i_hour_type = -1) Local $f_yyyymmdd = True If $s_type = -1 Or $s_type = Default Then $s_type = "yyyy/mm/dd" If Int($i_hour_type) = -1 Or $i_hour_type = Default Then $i_hour_type = 24 $i_hour_type = Int($i_hour_type) If $s_type <> "yyyy/mm/dd" Then $s_type = "mm/dd/yyyy" $f_yyyymmdd = False EndIf If $i_hour_type <> 24 And $i_hour_type <> 12 Then $i_hour_type = 24 Local $a_tick_count = DllCall("kernel32.dll", "int", "GetTickCount") If @error Then Return SetError(2, 0, "") Local $s_date_convert = _DateAdd("s", -Int($a_tick_count[0] / 1000), _NowCalc()) If $f_yyyymmdd And $i_hour_type = 24 Then Return $s_date_convert If Not $f_yyyymmdd And $i_hour_type = 24 Then Return StringRegExpReplace($s_date_convert, "(\d{4})(\W)(\d{2})(\W)(\d{2})(\W\d+\W\d+\W\d+)", "$3$2$5$2$1$6") EndIf Local $a_hourminsec = 0, $s_time = StringTrimLeft($s_date_convert, 11) Local $n_sre_min, $n_sre_sec, $s_meridian = "PM" If $i_hour_type = 12 Then $a_hourminsec = StringRegExp($s_date_convert, "(\d+\W\d+\W\d+\W)(\d+)(\W)(\d+)(\W)(\d+)", 1) If @error Then Return SetError(3, 0, "") $n_sre_hour = $a_hourminsec[1] $n_sre_min = $a_hourminsec[3] $n_sre_sec = $a_hourminsec[5] If Int($n_sre_hour) < 12 Then $s_meridian = "AM" If Int($n_sre_hour) = 0 Then $n_sre_hour = 12 If Int($n_sre_hour) > 12 Then $n_sre_hour = StringFormat("%02s", ($n_sre_hour - 12)) EndIf $s_time = $n_sre_hour & ":" & $n_sre_min & ":" & $n_sre_sec & " " & $s_meridian EndIf If $i_hour_type = 12 And $f_yyyymmdd Then Return StringLeft($s_date_convert, 11) & $s_time EndIf Return StringRegExpReplace($s_date_convert, "(\d{4})(\W)(\d{2})(\W)(\d{2})(.*?\z)", "$3$2$5$2$1 " & $s_time) EndFunc Edit: Just a note, this was thrown together quick and dirty... you may see issues with it, feel free to fix it if you do. Edited May 18, 2010 by SmOke_N Added example code Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now