Convert A_TickCount

Post your working scripts, libraries and tools
User avatar
jeeswg
Posts: 2967
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Convert A_TickCount

22 Nov 2017, 20:31

Here's an example script:
E.g. for days: you count the number of days (24-hour blocks).
E.g. for hours: you remove the days (any blocks of 24 hours), and count the number of hours.
E.g. for minutes: you remove the hours (any blocks of 60 minutes), and count the number of minutes.
E.g. for seconds: you remove the minutes (any blocks of 60 seconds), and count the number of seconds.

Code: [Select all] [Download] GeSHi © Codebox Plus

q:: ;tick count to date and friendly format
vSec := A_TickCount//1000
vDHMS := Format("{}d {}h {}m {}s", vSec//86400, Mod(vSec,86400)//3600, Mod(vSec,3600)//60, Mod(vSec,60))
vDate := A_Now
vDate += -vSec, S
;FormatTime, vDate, % vDate, HH:mm dd/MM/yyyy
FormatTime, vDate, % vDate, ddd yyyy-MM-dd HH:mm:ss
MsgBox, % "on at: " vDate "`r`n" "on for: " vDHMS
return
iPhilip
Posts: 222
Joined: 02 Oct 2013, 12:21

Re: Convert A_TickCount

23 Nov 2017, 01:54

That's great, jeeswg! I like how simple your approach is. :)
Windows 7 Pro (64 bit) - AutoHotkey v1.1+ (Unicode 32-bit)
User avatar
Lateralus138
Posts: 40
Joined: 30 Aug 2015, 20:52
Facebook: lateralus138
Google: +IanPride

Re: Convert A_TickCount

23 Nov 2017, 08:08

jeeswg wrote:Here's an example script:
E.g. for days: you count the number of days (24-hour blocks).
E.g. for hours: you remove the days (any blocks of 24 hours), and count the number of hours.
E.g. for minutes: you remove the hours (any blocks of 60 minutes), and count the number of minutes.
E.g. for seconds: you remove the minutes (any blocks of 60 seconds), and count the number of seconds.

Code: [Select all] [Download] GeSHi © Codebox Plus

q:: ;tick count to date and friendly format
vSec := A_TickCount//1000
vDHMS := Format("{}d {}h {}m {}s", vSec//86400, Mod(vSec,86400)//3600, Mod(vSec,3600)//60, Mod(vSec,60))
vDate := A_Now
vDate += -vSec, S
;FormatTime, vDate, % vDate, HH:mm dd/MM/yyyy
FormatTime, vDate, % vDate, ddd yyyy-MM-dd HH:mm:ss
MsgBox, % "on at: " vDate "`r`n" "on for: " vDHMS
return

Yes, very nice approach, I am going to turn this into a function for any number and post it here if you don't mind? Honestly, I should've thought of this approach. I read the docs and have seen the Format function before, but I forgot about it. Thanks for your script and inadvertent help with my ideas!

K̴̡̛̻̮̼͕̬̑̋̀̂͆͛̍̑͢ȩ̮̞͍̩̯̋̈͒͌̕ę̶͓̗͖͔̹̪͗̂̈͛̓͘p̠͉̙̟̒̊͌̐͘͘͟͡͞ S̸͖̖̮̞̥͇̖̓̌͛̽̿̓̊̓̾̚͜w͇̮͓̱͇̘̯͆̓͑̋̇̉͜͝i̢͔̝̳̻̱̋̾͐̾͗͊̀̕͜͡͡n̷̡͔̦̤̝̼̩̎͌̈́̀͛̄͆̎͠ǵ̸̘̝̭̦̠̗͖͌͐͑̑̿̅̈͜͜ḯ̡̬̥̙̩̼̪̑͆̿̌́n̛̼͎̲̬͇̲͉̗̞͊̓̃̂̈͝g̸͕̜͖̪͉͔̩̓̃̀̃͌̑̋̕͘.̪̜̜̜̯̂͂̈́͛̆͗̇̍̇.̟͔͍̙̜̫̗̂̿͛͋͋̈́̾̾̿͑.̡̣̟̝̭͉̦̪́̓̀͛̑̓̐̈͘͘

User avatar
noname
Posts: 405
Joined: 19 Nov 2013, 09:15

Re: Convert A_TickCount

23 Nov 2017, 09:31

Code: [Select all] [Download] (UpTime.ahk)GeSHi © Codebox Plus

;StrFromTimeInterval function  https://msdn.microsoft.com/en-us/library/windows/desktop/bb759980(v=vs.85).aspx

VarSetCapacity(uptime,256,0)
DllCall("Shlwapi.dll\StrFromTimeInterval",str,uptime, UInt,256, UInt,A_TickCount , Int,5)

Msgbox % uptime
User avatar
jeeswg
Posts: 2967
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Convert A_TickCount

23 Nov 2017, 10:41

- @Lateralus138: You're welcome to make a function from it, to change as little/as much as you want.
- @iPhilip: Cheers. I remember a long time ago dealing with Excel and the regular use of Mod and Floor divide when dealing with time.
- @noname: Nice, interesting Winapi function.
- Although this was possible from the day Format was created: Format("{}d {}h {}m {}s" and Format("{}x {}y {}w {}h", it took a lot of experimentation with Format and strings before I finally came up with the simple idea. I was looking at string concatenation and eventually realised that you could do {} repeatedly and pass lots of parameters.
Helgef
Posts: 2472
Joined: 17 Jul 2016, 01:02
Contact:

Re: Convert A_TickCount

23 Nov 2017, 13:16

The count is so that you can pass any number

That is fine, but I meant you do not need to assign count inside the function, this

Code: [Select all] [Download] GeSHi © Codebox Plus

toHours(count:=False){
Return stuff(count:=count?count:A_TickCount)
}

could be

Code: [Select all] [Download] GeSHi © Codebox Plus

toHours(count:=False){
Return stuff(count?count:A_TickCount)
}
;)
Nice one noname :wave:

Return to “Scripts and Functions”

Who is online

Users browsing this forum: No registered users and 16 guests