AutoHotkey Community

It is currently May 27th, 2012, 5:28 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: TimeToStr
PostPosted: January 3rd, 2006, 11:09 am 
Offline

Joined: July 22nd, 2005, 7:36 am
Posts: 52
Hi,

hase someone made an TimeToStr function
Example : TimeToStr(120)
will result :00:02:00

Andre


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 3rd, 2006, 3:51 pm 
Offline

Joined: July 22nd, 2005, 7:36 am
Posts: 52
Got it myself :) by looking on on the forum ....

Code:
TimeLog(T1)
{
   transform,S,MOD,T1,60
   stringlen,L1,S
   if L1 =1
   S=0%S%
   if S=0
   S=00

   M1 :=(T1/60)
   transform,M2,MOD,M1,60
   transform,M3,Floor,M2
   stringlen,L2,M3
   if L2 =1
   M3=0%M3%
   if M3=0
   M3=00

   H1 :=(M1/60)
   transform,H2,Floor,H1
   stringlen,L2,H2
   if L2=1
   H2=0%H2%
   if H2=0
   H2=00
   result= %H2%:%M3%:%S%
   return result
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 3rd, 2006, 5:08 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
FormatTime provides a simpler solution.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 4th, 2006, 8:02 am 
Offline

Joined: July 22nd, 2005, 7:36 am
Posts: 52
Laszlo,

could u provide an example, can't seem to fix it.

Andre


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 4th, 2006, 9:25 am 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
Hi, this is a mod of your code
Code:
MsgBox, % "this is the result of 7 " . TimeLog(7)
MsgBox, % "this is the result of 123 " . TimeLog(123)
MsgBox, % "this is the result of 4025 " . TimeLog(4025)

;T1 = value in seconds
TimeLog(T1)
  { 
     SetFormat, FLOAT, 02.0
     S := Mod(T1,60) + 0.0
     M := Mod((T1-S)/60,60)
     H := ((T1-S)/60 - M)/60
     return  H . ":" . M . ":" . S 
  }


@Laszlo: I do not see how to use FormatTime as well. Hope you can share some wisdome.

_________________
Ciao
toralf
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 4th, 2006, 2:31 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
toralf wrote:
@Laszlo: I do not see how to use FormatTime as well. Hope you can share some wisdome.
At first I didn't see it either, but I think you could use EnvAdd to add the incoming number of seconds to midnight of any date. Something like:

Code:
MsgBox % FormatSeconds(7384)  ; 7384 = 2 hours + 3 minutes + 4 seconds, yields: 02:03:04.

FormatSeconds(NumberOfSeconds)
; Convert up to 24 hours worth of seconds into hh:mm:ss format.
{
   Midnight = %A_YYYY%%A_MM%%A_DD%
   Midnight += %NumberOfSeconds%, seconds
   FormatTime, OutputVar, %Midnight%, HH:mm:ss  ; HH yields 24-hour format.
   return OutputVar
}

But the above will only work if the incoming seconds is under less than 24 hours worth of seconds, so Toralf, your approach seems better unless someone comes up with something simpler. I'll add it to the FormatTime page as an example.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 4th, 2006, 3:20 pm 
Laszlo wrote:
Quote:
FormatTime provides a simpler solution.
GO Laszlo GO :wink: (holy moly, shimanov has entered the scene :shock: :lol:) ...


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 4th, 2006, 6:40 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
...and if you want to go beyond one day
Code:
MsgBox % TimeLog(25*60*60+11*60+2)

TimeLog(Seconds)
{
   time = 20000101
   time+= %Seconds%, seconds
   FormatTime mmss, %time%, mm:ss
   FormatTime HH, %time%, HH
   FormatTime dd, %time%, dd
   return 24*(dd-1)+HH ":" mmss
}
but then it is not simpler than toralf's solution. Or, a hybrid:
Code:
TimeLog(Seconds)
{
   time = 20000101
   time+= %Seconds%, seconds
   FormatTime mmss, %time%, mm:ss
   return Seconds//3600 ":" mmss
}


Last edited by Laszlo on January 4th, 2006, 7:07 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 4th, 2006, 6:52 pm 
Offline

Joined: September 25th, 2005, 4:31 pm
Posts: 610
BoBo wrote:
shimanov has entered the scene


Fashionably late, as usual.

Code:
FormatSeconds( p_seconds )
{
   h := p_seconds//3600
   p_seconds := Mod( p_seconds, 3600 )
   
   m := p_seconds//60

   s := Mod( p_seconds, 60 )

   return, Chr( 48*( h < 10 ) ) h ":" Chr( 48*( m < 10 ) ) m ":" Chr( 48*( s < 10 ) ) s
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 4th, 2006, 7:19 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
Actually, toralf's solution can be written in just one line, with the global:
Code:
SetFormat FLOAT, 02.0
After that, we don't even need a function
Code:
MsgBox % Seconds//3600. ":" Mod(Seconds//60,60.) ":" Mod(Seconds,60.)
So, he is the champ.

Edit: using decimal points in the parameter makes the results FLOAT, displayed in 02.0 format


Last edited by Laszlo on January 5th, 2006, 1:40 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 4th, 2006, 9:27 pm 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
I think the championship goes to you, since you were the one to find the trivial solution. :)
But I guess the original request by Andre is best answered with the functions we all provided. I is now up to him to choose which to use.

_________________
Ciao
toralf
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 4th, 2006, 10:04 pm 
Offline

Joined: September 25th, 2005, 4:31 pm
Posts: 610
toralf wrote:
I think the championship goes to you


Toralf, the credit is yours. Without your insight, the final solution would remain undiscovered.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 4th, 2006, 10:12 pm 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
I disagree, since I only simplified Andres code. But thanks, you see me blush. *bow low*

_________________
Ciao
toralf
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 4th, 2006, 10:20 pm 
Offline

Joined: September 25th, 2005, 4:31 pm
Posts: 610
toralf wrote:
I disagree


That is certainly your right. But if you check the other codes, you will notice a marked difference, in which every other suggested solution lacked your insight. The key -- your insight -- was to perform automatic formatting using:

Code:
SetFormat, FLOAT, 02.0


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 5th, 2006, 3:46 am 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
Nice. I've added the enhanced version to the bottom of FormatTime. But I left it as a function since some people might prefer it that way.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Exabot [Bot], HotkeyStick, rbrtryn, Yahoo [Bot] and 79 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