[SOLVED] Better way to calc uptime

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
jNizM
Posts: 3183
Joined: 30 Sep 2013, 01:33
Contact:

[SOLVED] Better way to calc uptime

22 Oct 2013, 03:19

Is there a better (faster, Resource-saving) way to calc the uptime?

Code: Select all

MsgBox, % "Uptime: " FormatSeconds(DllCall("GetTickCount") / 1000)
MsgBox, % "Uptime: " FormatSeconds(DllCall("GetTickCount64") / 1000)

FormatSeconds(NumberOfSeconds, TimeFormat = "") {
    if !TimeFormat
        TimeFormat = HH:mm:ss
    Time = 19990101
    Time += %NumberOfSeconds%, Seconds
    FormatTime, Output1, %Time%, %TimeFormat%
	FormatTime, Output2, %Time%, YDay
    return Output2-1 "d:" Output1
}
Last edited by jNizM on 10 Feb 2014, 02:25, edited 1 time in total.
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
Zelio
Posts: 278
Joined: 30 Sep 2013, 00:45
Location: France

Re: Better way to calc uptime

22 Oct 2013, 21:33

It seems the best option and easy (like example of documentation), or maybe find a dynamic library to do it, or a machine code...
just me
Posts: 9457
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Better way to calc uptime

23 Oct 2013, 06:23

Maybe not better, but different:

Code: Select all

FormatDuration(NumberOfSeconds, Format := "d'd':hh:mm:ss") {
   ; http://msdn.microsoft.com/en-us/library/windows/desktop/dd318091(v=vs.85).aspx
   VarSetCapacity(Out, 128, 0)
   DllCall("Kernel32.dll\GetDurationFormat", "UInt", 0x400
                                           , "UInt", 0
                                           , "Ptr", 0
                                           , "Int64", NumberOfSeconds * 10000000
                                           , "WStr", Format
                                           , "WStr", Out
                                           , "Int", 64)
   Return Out
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Chunjee, rc76 and 326 guests