 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
HuBa
Joined: 24 Feb 2007 Posts: 175 Location: Budapest, Hungary
|
Posted: Sun Apr 22, 2007 1:39 am Post subject: Retrieve system Start time and Uptime |
|
|
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. | Code: | 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: | Code: | 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. |
|
| Back to top |
|
 |
garry
Joined: 19 Apr 2005 Posts: 2207 Location: switzerland
|
Posted: Sun Apr 22, 2007 9:43 am Post subject: |
|
|
köszönöm, jňl müködik
works fine  |
|
| Back to top |
|
 |
HuBa
Joined: 24 Feb 2007 Posts: 175 Location: Budapest, Hungary
|
Posted: Sun Apr 22, 2007 11:22 am Post subject: |
|
|
Glad you like it
Látom van itt pár magyar, de érdekes, hogy te sem laksz Mo-n. |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 7279 Location: Australia
|
Posted: Mon Apr 23, 2007 8:01 am Post subject: Re: Retrieve system Start time and Uptime |
|
|
| HuBa wrote: | | 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). I had to occasionally restart Winamp and Azureus - which apparently leaked memory - but other than that, I rarely have problems with Windows XP. [/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... | Code: | 0 days 0:39:6
;vs
0 days 0:39:06 |
|
|
| Back to top |
|
 |
HuBa
Joined: 24 Feb 2007 Posts: 175 Location: Budapest, Hungary
|
Posted: Mon Apr 23, 2007 10:31 am Post subject: |
|
|
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. |
|
| Back to top |
|
 |
brasildeluna Guest
|
Posted: Tue Nov 08, 2011 11:38 pm Post subject: |
|
|
| HuBa wrote: | 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. |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|