Convert A_TickCount

Post your working scripts, libraries and tools for AHK v1.1 and older
iPhilip
Posts: 814
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 10 Pro (64 bit) - AutoHotkey v2.0+ (Unicode 64-bit)
User avatar
Lateralus138
Posts: 49
Joined: 30 Aug 2015, 20:52
Location: Decatur, IL.
Contact:

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

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: 515
Joined: 19 Nov 2013, 09:15

Re: Convert A_TickCount

23 Nov 2017, 09:31

Code: Select all

;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: 6902
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.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Helgef
Posts: 4709
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

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

Code: Select all

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

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: dipahk and 74 guests