AutoHotkey Community

It is currently May 25th, 2012, 2:23 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: April 22nd, 2007, 2:39 am 
Offline

Joined: February 24th, 2007, 6:02 pm
Posts: 175
Location: Budapest, Hungary
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 22nd, 2007, 10:43 am 
Offline

Joined: April 19th, 2005, 10:26 am
Posts: 2248
Location: switzerland
köszönöm, jòl müködik
works fine :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 22nd, 2007, 12:22 pm 
Offline

Joined: February 24th, 2007, 6:02 pm
Posts: 175
Location: Budapest, Hungary
Glad you like it :)
Látom van itt pár magyar, de érdekes, hogy te sem laksz Mo-n.


Report this post
Top
 Profile  
Reply with quote  
PostPosted: April 23rd, 2007, 9:01 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7501
Location: Australia
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). 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...
Code:
0 days 0:39:6
;vs
0 days 0:39:06


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 23rd, 2007, 11:31 am 
Offline

Joined: February 24th, 2007, 6:02 pm
Posts: 175
Location: Budapest, Hungary
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 9th, 2011, 12:38 am 
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.


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: lblb and 20 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group