AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Retrieve system Start time and Uptime

 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
HuBa



Joined: 24 Feb 2007
Posts: 175
Location: Budapest, Hungary

PostPosted: Sun Apr 22, 2007 1:39 am    Post subject: Retrieve system Start time and Uptime Reply with quote

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
View user's profile Send private message Visit poster's website
garry



Joined: 19 Apr 2005
Posts: 2207
Location: switzerland

PostPosted: Sun Apr 22, 2007 9:43 am    Post subject: Reply with quote

köszönöm, jňl müködik
works fine Smile
Back to top
View user's profile Send private message
HuBa



Joined: 24 Feb 2007
Posts: 175
Location: Budapest, Hungary

PostPosted: Sun Apr 22, 2007 11:22 am    Post subject: Reply with quote

Glad you like it Smile
Látom van itt pár magyar, de érdekes, hogy te sem laksz Mo-n.
Back to top
View user's profile Send private message Visit poster's website
Lexikos



Joined: 17 Oct 2006
Posts: 7279
Location: Australia

PostPosted: Mon Apr 23, 2007 8:01 am    Post subject: Re: Retrieve system Start time and Uptime Reply with quote

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). Cool I had to occasionally restart Winamp and Azureus - which apparently leaked memory - but other than that, I rarely have problems with Windows XP. Very Happy [/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
View user's profile Send private message Visit poster's website
HuBa



Joined: 24 Feb 2007
Posts: 175
Location: Budapest, Hungary

PostPosted: Mon Apr 23, 2007 10:31 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
brasildeluna
Guest





PostPosted: Tue Nov 08, 2011 11:38 pm    Post subject: Reply with quote

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
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group