Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Retrieve system Start time and Uptime


  • Please log in to reply
5 replies to this topic
HuBa
  • Members
  • 175 posts
  • Last active: Feb 13 2012 09:51 AM
  • Joined: 24 Feb 2007
I was searching the forum for some good uptime calculator script.
I found several ones but I'm just not satisfied with them, they are too complicated in my opinion.

Well here is my solution that displays the starting time of the system and the elapsed time since start (the uptime).
I think it is simplified enough and gives opportunity for easy customization.
t_TimeFormat := "HH:mm:ss"
t_StartTime :=                          ; Clear variable = A_Now
t_UpTime := A_TickCount // 1000         ; Elapsed seconds since start
t_StartTime += -t_UpTime, Seconds       ; Same as EnvAdd with empty time
FormatTime t_NowTime, , %t_TimeFormat%  ; Empty time = A_Now
FormatTime t_StartTime, %t_StartTime%, %t_TimeFormat%
t_UpTime := % t_UpTime // 3600 ":" mod(t_UpTime // 60, 60) ":" mod(t_UpTime, 60)
MsgBox 64, Uptime, % "Start time: `t" t_StartTime "`nTime now:`t" t_NowTime "`n`nElapsed time:`t" t_UpTime
This does not shows the day number in uptime, just the hours.

If you rarely switch off the computer you might want to see the days too, then try this:
t_TimeFormat := "HH:mm:ss dddd"
t_StartTime :=                          ; Clear variable = A_Now
t_UpTime := A_TickCount // 1000         ; Elapsed seconds since start
t_StartTime += -t_UpTime, Seconds       ; Same as EnvAdd with empty time
FormatTime t_NowTime, , %t_TimeFormat%  ; Empty time = A_Now
FormatTime t_StartTime, %t_StartTime%, %t_TimeFormat%
t_UpTime := % t_UpTime // 86400 " days " mod(t_UpTime // 3600, 24) ":" mod(t_UpTime // 60, 60) ":" mod(t_UpTime, 60)
MsgBox 64, Uptime, % "Start time: `t" t_StartTime "`nTime now:`t" t_NowTime "`n`nElapsed time:`t" t_UpTime
You can remove the t_StartTime := line if you are going to use the script inside a function or if you execute it only once in the script's lifetime.

garry
  • Spam Officer
  • 3219 posts
  • Last active: Sep 20 2018 02:47 PM
  • Joined: 19 Apr 2005
köszönöm, jòl müködik
works fine :)

HuBa
  • Members
  • 175 posts
  • Last active: Feb 13 2012 09:51 AM
  • Joined: 24 Feb 2007
Glad you like it :)
Látom van itt pár magyar, de érdekes, hogy te sem laksz Mo-n.

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006

If you rarely switch off the computer you might want to see the days too,

[OT] Hahaha! I remember when I started learning C#, one of the first things I did was an up-time calculator. At one point, my computer had been up and running for over 3 weeks (some 500+ hours). 8) I had to occasionally restart Winamp and Azureus - which apparently leaked memory - but other than that, I rarely have problems with Windows XP. :D [/OT]

Good idea with the "Start time," I just had "Elapsed time" (hours, minutes, seconds.)

I think it looks a bit odd without padding, though...
0 days 0:39:6
;vs
0 days 0:39:06


HuBa
  • Members
  • 175 posts
  • Last active: Feb 13 2012 09:51 AM
  • Joined: 24 Feb 2007
I know the leading zero is a problem in the "Elapsed time".
I don't know how to solve it in a single line of code.
I could do it with 3 more lines but I think it's a very simple function, I want to keep it simple.

brasildeluna
  • Guests
  • Last active:
  • Joined: --

I know the leading zero is a problem in the "Elapsed time".
I don't know how to solve it in a single line of code.
I could do it with 3 more lines but I think it's a very simple function, I want to keep it simple.


Thanks a bunch, this is awesome!
Congratulations on a great, simple solution.